[英]Today as the basic date and then count Nth day's `day-week` during 5 years before and after
例如:
如果 N 是第 13 天,基本日期是今天,那么我希望调用一些函数或视图或 sp 来获得前后 5 年中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
这是你想要的吗?
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.