首先,我已经搜索过网站,找不到任何可以达到我需要的结果。
以下是我要做的事情:
id calldate disposition user_id
1 12/16/2012 21:34 ANSWERED 21
2 12/16/2012 21:34 ANSWERED 21
3 12/16/2012 21:59 ANSWERED 21
4 12/16/2012 22:11 ANSWERED 21
5 12/16/2012 22:11 FAILED 21
现在我想计算同时插入的行数(对应行的时间和状态)。
因此,对于上述记录,结果将类似于:
calldate count
12/16/2012 21:34 2
12/16/2012 21:59 1
这是我到目前为止所取得的成绩,但仍然无法取得预期的成果。
SELECT
COUNT(*) AS total,
DATE(calldate) AS date,
HOUR(calldate) AS hour,
calldate
FROM calls
WHERE disposition='ANSWERED'
GROUP BY date, hour HAVING total > 1 ORDER BY calldate ASC
任何帮助都将受到高度赞赏。
谢谢
答案 0 :(得分:0)
这样做你想要的吗?
SELECT calldate, COUNT(*) AS total
FROM calls
WHERE disposition = 'ANSWERED'
GROUP BY calldate
HAVING total > 1
ORDER BY calldate ASC;