【发布时间】:2020-05-30 01:26:09
【问题描述】:
我正在尝试创建一个查询,将轮班生产划分为每小时计数,这些计数可以通过多个班次运行,但每个班次的前几个小时属于相同的计数。
Sum(CASE WHEN DATEPART(HOUR,[creation_time]) = '1' THEN quantity_increment_D ELSE 0 END) C1,
Sum(CASE WHEN DATEPART(HOUR,[creation_time]) = '2' THEN quantity_increment_D ELSE 0 END) C2,
Sum(CASE WHEN DATEPART(HOUR,[creation_time]) = '3' THEN quantity_increment_D ELSE 0 END) C3,
在我的报告中,这个查询对于一天的第一班工作正常,但第二班和第三班不会在 C1 上重新开始。我基本上需要问一些事情:
If(shift_id_S)='1' then sum(quantity_increment_D) where (creation_time) between '00:00:00' and'07:59:59' as C1
If(shift_id_S)='2' then sum(quantity_increment_D) where (creation_time) between '08:00:00' and'15:59:59' as C1
If(shift_id_S)='3' then sum(quantity_increment_D) where (creation_time) between '16:00:00' and'23:59:59' as C1
If(shift_id_S)='4' then sum(quantity_increment_D) where (creation_time) between '00:00:00' and'11:59:59' as C1
If(shift_id_S)='5' then sum(quantity_increment_D) where (creation_time) between '12:00:00' and'23:59:59' as C1
如果我可以就这部分查询获得帮助,我可以处理其余的计数。
【问题讨论】:
标签: sql reporting-services sum ssms