[英]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. 我知道这是一个小组成员,但我对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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.