Rocco The Taco Rocco The Taco - 6 months ago 11
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

DATE(ScheduleDateExact,%Y-%m-%d)
.

What am I doing wrong?

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

Answer

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
GROUP BY DAYOFWEEK(DATE(ScheduleDateExact))