2
我有一個日誌條目的數據庫,如:計數條目日誌到MySQL
CREATE TABLE `cheaters` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`date` datetime NOT NULL,
`guid` int(10) unsigned NOT NULL,
`type` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `guid` (`guid`)
) ENGINE=InnoDB AUTO_INCREMENT=973997 DEFAULT CHARSET=utf8
的樣本數據:
mysql> select * from cheaters LIMIT 10;
+----+---------------------+-------+-------------------------------+
| id | date | guid | type |
+----+---------------------+-------+-------------------------------+
| 1 | 2011-12-15 18:16:16 | 17567 | Speed-Hack detected |
| 2 | 2011-12-15 18:16:28 | 69460 | Speed-Hack detected |
| 3 | 2011-12-15 18:16:29 | 82077 | Walk on Water - Hack detected |
| 4 | 2011-12-15 18:16:50 | 55710 | Speed-Hack detected |
| 5 | 2011-12-15 18:16:50 | 84229 | Speed-Hack detected |
| 6 | 2011-12-15 18:16:52 | 55848 | Speed-Hack detected |
| 7 | 2011-12-15 18:16:53 | 48774 | Speed-Hack detected |
| 8 | 2011-12-15 18:16:54 | 48774 | Speed-Hack detected |
| 9 | 2011-12-15 18:16:56 | 48092 | Speed-Hack detected |
| 10 | 2011-12-15 18:16:56 | 81389 | Speed-Hack detected |
+----+---------------------+-------+-------------------------------+
我希望得到一些東西一樣:
+------------+---------------------+-------+
| DAY | GUID | COUNT |
+------------+---------------------+-------+
| 2011-12-15 | 17567 | 356 |
| 2011-12-15 | 69123 | 6 |
.... ....
| 2011-12-16 | 69123 | 8 |
.... ....
這是每個guid每天的條目數。 我怎樣才能得到它?哪個查詢?
謝謝。
如果總數大於X,我可以過濾結果嗎? – xkill 2011-12-18 18:54:58
查看我更新的答案。 – 2011-12-18 19:19:47