[英]Today as the basic date and then count Nth day's `day-week` during 5 years before and after
eg:例如:
If N is 13th and the basic date is today then i hope calling some function or view or sp to get 13th
day's day-week
group count during 5 years before and after如果 N 是第 13 天,基本日期是今天,那么我希望调用一些函数或视图或 sp 来获得前后 5 年中
13th
天的day-week
组计数
Expected:预期的:
If today is 2020-02-03
then the expected data :如果今天是
2020-02-03
那么预期数据:
dayOfWeek,count
1,16
2,19
3,16
4,19
5,15
6,18
7,17
What i have tried :我试过的:
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
Is this what you want?这是你想要的吗?
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.