Rocco The Taco Rocco The Taco - 2 years ago 83
SQL Question

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. I am getting a syntax error even though I've tried to also include


What am I doing wrong?

FROM ScheduleRequest
GROUP BY DAYOFWEEK (DATE(ScheduleDateExact)) FROM ScheduleRequest

Answer Source

You have a redundant from clause after the group by clause. 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   DAYOFWEEK(DATE(ScheduleDateExact)), COUNT(WorkOrderNum)
FROM     ScheduleRequest
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download