SQL查询中的区别和连接?

时间:2015-09-21 08:59:35

标签: mysql sql

我正在尝试为同一设备获取不同的eSignDeviceCode但是对于每个eSignDeviceCode我都会获得一个新行。

 select 
     count(distinct(eSignDeviceCode)) as units,
     (f.devicename) as devicename,
     (CASE WHEN u.Status=1 THEN  count(u.Status) ELSE 0  END) AS intit,
     (CASE WHEN u.Status=2 THEN  count(u.Status) ELSE 0  END) AS ekyc,
     (CASE WHEN u.Status=4 THEN count(u.Status)  ELSE 0  END) AS esign 
 from applicationdetails u 
 left join esignlogs e  
   on e.ApplicationSlNo=u.SlNo  
 LEFT JOIN fingerprintdevice AS f 
   ON f.SlNo=e.DeviceId  group by e.eSignDeviceCode;

1 个答案:

答案 0 :(得分:1)

您的group by子句错了。试试这个: -

INSERT INTO sendMsg (Type,Name,SenderName,Message) 
SELECT 4, "name" ,'Mike','Hi, blabla' FROM anothertable
-- WHERE ....