Edward Glasser
Edward Glasser

Reputation: 193

SQL group by DATENAME

I'm trying to get a count of rows for each day of the week between a certain date.

so far I have:

SELECT DATENAME(weekday,Date) AS theDay FROM tablename WHERE year(date) = '2013' and (month(date) >= 5 AND month(date) <= 7)

this gives me something like this:

Wednesday
Wednesday
Wednesday
Wednesday
Wednesday
Thursday
Thursday
Friday
Friday
Friday
Friday
Saturday
Saturday

But I'd like for it to be like

Wednesday

and then in the next column

5

and so on. I know this is a group by, but I'm not that great with SQL.

Upvotes: 1

Views: 2756

Answers (1)

Sonam
Sonam

Reputation: 3466

SELECT DATENAME(weekday,Date) AS theDay,count(*) NumberOfDays
FROM tablename 
WHERE year(date) = '2013' and (month(date) >= 5 AND month(date) <= 7)
group by DATENAME(weekday,Date)

Upvotes: 1

Related Questions