2

有 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                   | 

任何帮助表示赞赏!

谢谢

4

2 回答 2

7
select DATE(created), count(id) from user group by DATE(created);
于 2009-06-02T22:46:21.807 回答
1
SELECT DATE(created) as date, count(1) as nrRegistered
FROM user
GROUP BY date

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

于 2009-06-02T22:48:22.320 回答