我有一张数据如下的表,
detectDate |isp |infection | count -------------------------------------- 2012-10-02 01:00|aaaa |malware |3 2012-10-02 01:30|bbbb |malware |2 2012-10-02 01:33|bbbb |spy-eye |2 2012-10-02 01:45|aaaa |DDos |1 2012-10-03 01:50|cccc |malware |2 2012-10-03 02:00|dddd |TDSS |2 2012-10-03 04:50|dddd |TDSS |3
我需要这样的输出,按日期和感染分组,
detectDate |infection | count -------------------------------------- 2012-10-02 |malware |5 2012-10-02 |spy-eye |2 2012-10-02 |DDos |1 2012-10-03 |malware |2 2012-10-03 |TDSS |5
我知道一般如何使用分组,但不知道他的远:(您能帮我吗,我需要按日期和感染分组,并获得如图所示的计数字段的总数。
使用SUM函数对count列求和并使用DATE_FORMAT函数仅按日期分组。
SUM
count
DATE_FORMAT
SELECT DATE_FORMAT(detectDate, '%Y-%m-%d') AS detectDate ,infection ,SUM(`COUNT`) as `count` FROM myTable GROUP BY DATE_FORMAT(detectDate, '%Y-%m-%d'), infection