我正在使用具有此类字段的用户表
id
username
email
created_at(unix timestamp)
现在我希望按月分组当前年度数据。 像这样的东西
month/week count(*)
jan(1) 55
jan(2) 102
jan(3) 23
jan(4) 39
feb(1) 6
feb(2) 14
feb(3) 37
feb(4) 20
. .
. .
. .
. .
. .
答案 0 :(得分:1)
检查 DATE / TIME 功能
SELECT MONTH(created_at), WEEK(created_at), count(*)
FROM YourTable
WHERE YEAR(created_at) = YEAR(NOW())
GROUP BY MONTH(created_at), WEEK(created_at)