Mysql计数用户列,并按修改日期分组

时间:2009-06-02 22:42:44

标签: mysql select count

我想要数据来自2列。基本上我想每天看到新的注册。对我来说很容易,我的第一天使用mysql(或任何数据库)

到目前为止,我有这个

mysql> select created, count(id) from user group by created;
+---------------------+-----------+
| created             | count(id) |
+---------------------+-----------+
| 2009-05-27 00:58:56 |         1 | 
| 2009-05-27 01:27:30 |         1 | 
| 2009-05-27 02:35:37 |         1 | 
| 2009-05-27 02:58:56 |         1 | 
| 2009-05-27 03:36:03 |         1 | 
| 2009-05-27 03:38:03 |         1 | 
| 2009-05-27 03:48:16 |         1 | 
| 2009-05-27 03:51:37 |         1 | 

我想要的输出是

+---------------------+----------------------+
| created             | user                 |
+---------------------+----------------------+
| 2009-05-27          | 10                   |
| 2009-05-28          | 13                   | 
| 2009-05-29          | 19                   | 

感谢任何帮助!

由于

2 个答案:

答案 0 :(得分:7)

select DATE(created), count(id) from user group by DATE(created);

答案 1 :(得分:1)

SELECT DATE(created) as date, count(1) as nrRegistered
FROM user
GROUP BY date

注意:通过计算1而不是id,我们避免在表中查找并启用仅索引查询