简体   繁体   English

MySQL COUNT 按星期几

[英]MySQL COUNT by Day of Week

Using a variation of the answer here using Group By, I'm trying to do a count of how many records occurred on each day of the week and display the count by the day of the week.使用此处使用 Group By 的答案变体,我试图计算一周中每一天发生的记录数,并按一周中的某天显示计数。 I am getting a syntax error even though I've tried to also include DATE(ScheduleDateExact,%Y-%m-%d) .即使我尝试还包含DATE(ScheduleDateExact,%Y-%m-%d)我仍然收到语法错误。

What am I doing wrong?我究竟做错了什么?

SELECT COUNT(WorkOrderNum)
FROM ScheduleRequest
GROUP BY DAYOFWEEK (DATE(ScheduleDateExact)) FROM ScheduleRequest

You have a redundant from clause after the group by clause.group by子句之后有一个多余的from子句。 Get rid of it, and you should be fine.摆脱它,你应该没事。 I recommend, however, you add the day-of-week extraction to the select list too, so you can easily understand the results you're getting:但是,我建议您也将星期几提取添加到select列表中,以便您可以轻松了解获得的结果:

SELECT   DAYOFWEEK(DATE(ScheduleDateExact)), COUNT(WorkOrderNum)
FROM     ScheduleRequest
GROUP BY DAYOFWEEK(DATE(ScheduleDateExact))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM