我正在尝试获取特定日期之间一周中每一天的行数。
到目前为止,我有:SELECT DATENAME(weekday,Date) AS theDay FROM tablename WHERE year(date) = '2013' and (month(date) >= 5 AND month(date) <= 7)
这给了我这样的东西:
Wednesday
Wednesday
Wednesday
Wednesday
Wednesday
Thursday
Thursday
Friday
Friday
Friday
Friday
Saturday
Saturday
但我希望它像
Wednesday
然后在下一栏
5
等等。我知道这是一个小组,但我对SQL并不是那么好。
答案 0 :(得分:1)
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)