我正在尝试为用户注册制作每周统计数据.它应该每周工作.一周总共七天.我想在屏幕上打印一周中每天注册的用户数.
例如:
Number of users who registered on Monday = 38
Number of users who registered on Tuesday = 11
…. …. and this list will only list the week we were
SELECT WEEKDAY(registerTime)+1, count(*)
FROM users group by WEEKDAY(registerTime)
ORDER BY WEEKDAY(registerTime)
但这个问题的结果却截然不同.此总数显示每周一在星期一注册的用户数.
解决方法:
SELECT WEEKDAY(registerTime)+1, count(*)
FROM users
WHERE WEEKOFYEAR(registerTime) = WEEKOFYEAR(CURDATE())
AND YEAR(registerTime) = YEAR(CURDATE())
group by WEEKDAY(registerTime)
ORDER BY WEEKDAY(registerTime);
基本上,您将一年中的一年和一周与您需要的相匹配.那应该够了.