0

我正在尝试获取某个日期之间一周中每一天的行数。

到目前为止,我有:

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

等等。我知道这是一个 group by,但我对 SQL 不是很好。

4

1 回答 1

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)
于 2013-07-31T16:04:47.457 回答