为什么下面的查询只给出了每个SmartRouterSessions和NonSmartRouterSessions的总数(即Smart + NonSmartSessions)?

时间:2014-04-02 23:05:36

标签: sql oracle toad

SELECT  MAX(TO_CHAR(DTM_LAST_MODIFIED,'MM/DD/YYYY')) As JobCompletionDate,
             MAX(TO_CHAR(DTM_LAST_MODIFIED,'HH24:MI:SS')) As JobCompletionTime,
             COUNT('Select * from wfimgr.device_usage where  SERVICE_NAME in ("WIFILOC9","WIFIDEV9")') As SmartRouterSessions,
             COUNT('Select * from wfimgr.device_usage where SERVICE_NAME NOT IN ("WIFILOC9","WIFIDEV9")') As NonSmartRouterSessions
FROM wfimgr.device_usage WHERE DTM_LAST_MODIFIED BETWEEN '28-MAR-2014' AND '29-MAR-2014' 

1 个答案:

答案 0 :(得分:2)

这可能会让你得到你想要的东西:

SELECT MAX(TO_CHAR(DTM_LAST_MODIFIED, 'MM/DD/YYYY')) As JobCompletionDate,
       MAX(TO_CHAR(DTM_LAST_MODIFIED, 'HH24:MI:SS')) As JobCompletionTime,
       sum(case when service_name in ('WIFILOC9','WIFIDEV9') then 1 else 0 end) as SmartRouterSessions
       sum(case when service_name not in ('WIFILOC9','WIFIDEV9') then 1 else 0 end) as NonSmartRouterSessions
  FROM wfimgr.device_usage
 WHERE DTM_LAST_MODIFIED BETWEEN '28-MAR-2014' AND '29-MAR-2014'