日期:2014-05-16  浏览次数:20516 次

谁来把这个distinct换成exists
SELECT LICENSE_NAME,USER_GROUP_NAME, AVG(USAGE) AS USAGE,
AVG(LICENSE_TOTAL) AS LICENSE_TOTAL,count(distinct CHECKOUTTIME) AS USERASKTIMES
FROM FLEXLM_LICENSE_USAGE a LEFT JOIN user_group as b
ON a.USER_NAME = b.USER_NAME and a.sampling_time = b.sampling_time
WHERE a.sampling_time >='2013-03-01 00:00:00' and a.sampling_time <'2013-03-31 00:00:00'
  AND to_char(a.sampling_time, 'mi')='00'
GROUP BY USER_GROUP_NAME,LICENSE_NAME
ORDER BY USER_GROUP_NAME;

这个SQL执行后,发现主要时间耗在了count(distinct CHECKOUTTIME)上,因此想想其换种写法试试,自己写了下没写出来,请大侠们来讨论下