如何将所有星期的差异列值转换为每周的开始日期?
样本数据:
Week Diff | Value
1 | 20000
2 | 30000
3 | 40000
预期结果:
Week Diff | Value
6/24/2018 | 20000
6/17/2018 | 30000
6/10/2018 | 40000
我看过类似的帖子,但是我不明白如何根据自己的需要更改解决方案。例如
declare @wk int = week_diff
select dateadd(week,@wk-1, DATEADD(wk, DATEDIFF(wk,-1,DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)), 0))
请告知。
答案 0 :(得分:0)
尝试一下:
select
convert(date,DATEADD(wk, DATEDIFF(wk,0,getdate())-[Week Diff], 0))
from yourtable