例如:
如果N是13,而基本日期是今天,那么我希望调用一些函数、视图或sp来获得13th日前后的day-week组计数。
预期:
如果今天是2020-02-03,那么预期的数据:
dayOfWeek,count
1,16
2,19
3,16
4,19
5,15
6,18
7,17我试过的是:
declare @now date = '2020-2-3';
declare @TheDateBefore5Years date = dateadd(year,-5,@now)
,@TheDateAfter5Years date = dateadd(year,5,@now)
;
with cte as (
//....
)
select dayOfWeek,count(1) count
from cte
group by dayOfWeek发布于 2020-02-03 14:10:13
这是你想要的吗?
select datepart(dow, datecol), count(1) count
from t
where datecol >= dateadd(year, -5, '2020-02-03') and
datecol <= dateadd(year, 5, '2020-02-03')
group by datepart(dow, datecol)https://stackoverflow.com/questions/60040560
复制相似问题