简体   繁体   中英

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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