sql server 按上周五到本周四为一周汇总数据怎么写代码
一般情况下,周值都是从周日~周六为一周;现在要实现「周五~周四」为统计周,将日期往后加2天或往前减5天,再分组统计即可;
-- 参考脚本:
select
datename(wk,dateadd(dd,2,日期字段)) as wk,
sum(km)
from tabname group by datename(wk,dateadd(dd,2,日期字段))
——————————————————
"你的日期字段" BETWEEN DATEADD(wk, DATEDIFF(wk,0,getdate()), -3) AND DATEADD(wk, DATEDIFF(wk,0,getdate()), 3)