在 mySQL 中,我想做的是查询我的表并找出每天有多少人注册。换句话说,我希望能够在一个月内产生以下输出:
1 January: 10 registrations
2 January: 150 registrations
3 January: 50 registrations
select created, regID
from registrations
数据库中的日期格式如下:2012-11-01 00:00:00
在 mySQL 中,我想做的是查询我的表并找出每天有多少人注册。换句话说,我希望能够在一个月内产生以下输出:
1 January: 10 registrations
2 January: 150 registrations
3 January: 50 registrations
select created, regID
from registrations
数据库中的日期格式如下:2012-11-01 00:00:00
要获取 1 月每一天的注册计数,请使用以下命令select
:
select daymonth(registration_date), count(*)
from registrations
where registration_date >= '01/01/2012' and registration_date <= '01/31/2012'
group by daymonth(registration_date)
您通常使用分组运算符:
SELECT COUNT(*) AS registrations, DATE(created) AS created_date GROUP BY created_date
如果created
已经是一DATE
列,则不需要转换。
试试这个:
SELECT created, count(regID) FROM registrations GROUP BY created ORDER BY created ASC
SELECT DATE(DATE_REGISTERED) DATE, COUNT(*) totalRegistered
FROM tableName
GROUP BY DATE