我有以下内容:
SELECT COUNT(*),DAYNAME(sip_Date) AS DAY,sip_callid FROM request_line WHERE DAYNAME(sip_Date) = 'Saturday' GROUP BY sip_callid;
输出:
+----------+----------+-------------------------------------+ | COUNT(*) | DAY | sip_callid | +----------+----------+-------------------------------------+ | 6 | Saturday | 133E840E-F6A411DE-AA5C9CC8-17D97B68 | | 6 | Saturday | 162BF117-F6A611DE-A986A3C8-FB0ED04D | | 18 | Saturday | 163C78CD-F6A611DE-9FC6D5B8-87CB70FC | | 12 | Saturday | 1A7C93B6-F6A711DE-91F4BA52-B031BEF4 | | 6 | Saturday | 1AB2BC9C-F6A311DE-A972A3C8-FB0ED04D | | 4 | Saturday | 1F7E3D6C-F6AC11DE-A045D5B8-87CB70FC | | 4 | Saturday | 1FA68517-F6AC11DE-A048D5B8-87CB70FC | | 4 | Saturday | 1FCECD5A-F6AC11DE-A04AD5B8-87CB70FC | | 4 | Saturday | 1FEDED7C-F6AC11DE-A04DD5B8-87CB70FC | | 6 | Saturday | 2625EFE-F6A311DE-A96FA3C8-FB0ED04D | +----------+----------+-------------------------------------+
但我需要每天计算每个唯一的“sip_callid”,所以我需要一个像这样的输出:
+----------+----------+ | COUNT(*) | DAY | +----------+----------+ | 70 | Saturday |
但我似乎无法通过sip_callid与一组人一起做。如果我按DAY进行分组,那么即使sip_callid明显相同,我也会获得所有行。 任何帮助将不胜感激。
答案 0 :(得分:2)
我认为你需要COUNT(DISTINCT)
像这样的东西
SELECT DAYNAME(sip_Date) AS DAY,
COUNT(DISTINCT sip_callid)
FROM request_line
WHERE DAYNAME(sip_Date) = 'Saturday'
GROUP BY DAYNAME(sip_Date)