可能重复:
过去 7 天的 MySQL 计数数据
我有一个问题,我需要显示字段的总和。假设我有一个记录集如下,
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 |DDos |1
2012-10-02 |malware |5
2012-10-02 |spy-eye |2
2012-10-02 |TDSS |0
2012-10-03 |DDos |0
2012-10-03 |malware |2
2012-10-03 |spy-eye |0
2012-10-03 |TDSS |5
我使用了这个查询,
SELECT DATE_FORMAT( detectDate, '%Y-%m-%d' ) AS detectDate, infection, SUM( count )
FROM `tbl_correlateddata`
GROUP BY DATE_FORMAT( detectDate, '%Y-%m-%d' ) , infection
但它只给出如下输出,这不是我的要求..
detectDate |infection | count
-------------------------------
2012-10-02 |DDos |1
2012-10-02 |malware |5
2012-10-02 |spy-eye |2
2012-10-03 |malware |2
2012-10-03 |TDSS |5
任何帮助都会很有帮助:)非常感谢:)非常感谢:)
编辑: 可能重复:MySQL Count data for last 7 days
但不相似