几周没有价值的周数累计金额

时间:2017-05-10 16:34:21

标签: sql-server

我正在使用此查询来获得滚动的5周总和

select reportdate,
    department,
    count(orders) as count,
    sum(count(orders)) over (
        partition by department order by reportdate rows between 4 preceding and current row
        ) as 5 weeksum
from orders

sum(count(orders)在每个reportdate每个部门都有值时工作正常。 但是,如果某些报告日期没有订单,则总和(计数(订单))不起作用。

例如。

reportdate 1-Jan Dept A count(Orders) is 10
7-Jan dept A 'NO ORDERS' which means blank column
14-Jan dept A count(Orders) is 12
21-Jan dept A count(Orders) is 14
28-jan dept A count(Orders) is 25
31-jan dept A count(Orders) is 5

总和(计数(订单))

的结果
1-Jan 10
7-Jan BLANK 
 while I expect 7-Jan to show 10 

有关如何实现的任何建议吗?

0 个答案:

没有答案