Rocco The Taco
Rocco The Taco

Reputation: 3777

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

Upvotes: 4

Views: 3311

Answers (1)

Mureinik
Mureinik

Reputation: 311073

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))

Upvotes: 4

Related Questions