lxy2 回复 狂奔的小蜗牛(提问者)
with a as(
select \'2022-11-01\' as a,4 as b
union all
select \'2022-11-02\' as a,4 as b
union all
select \'2022-11-03\' as a,3 as b
union all
select \'2022-11-04\' as a,2 as b
union all
select \'2022-11-05\' as a,1 as b
union all
select \'2022-11-06\' as a,6 as b
union all
select \'2022-11-07\' as a,6 as b
)
select *,dateName(dw,a) as weekdates from a where dateName(dw,a)=\'星期一\'--参考
lxy2 回复 狂奔的小蜗牛(提问者)每个月只要汇总周一的数据的话,可以这么写 select 月份,sum(case when dateName(dw,日期)=\'星期一\' then isnull(汇总数值字段,0) else 0 end ) as 总数量,月份 from 表名 group by 月份 或者直接日期只要星期一的select 月份,sum( isnull(汇总数值字段,0) ) as 总数量,月份 from 表名 where dateName(dw,日期)=\'星期一\'group by 月份
vk 回复 狂奔的小蜗牛(提问者)SQL SERVER 没咋用过, 这代码where后面加上你的那些条件试试
SELECT
Z1MON,
Z1STMP,
SUM(BEHHZ)
FROM
DBO.ZNMS_JIT_Z2_FXHZ_MBS
WHERE DATEPART(DW,Z1STMP)=2
GROUP BY Z1MON