首页 > 解决方案 > SQL 查询在其间的几周内返回 0

问题描述

我有这个有效的查询,但结果不是我想要的

只返回有数据的年和周,我想返回 0 到结果

例如这返回

year    week   totalstop
2017    50     7
2018    1      3
2018    3      5

但我想回来

year    week   totalstop
2017    50     7
2017    51     0
2017    52     0
2018    1      3
2018    2      0
2018    3      5

等等

这是当前查询

SELECT year(Stopdate)[year],datepart(week,date1) [week],sum(stop) totalstop 
        from Table1 where 
        building in (select item from dbo.fn_Split('A1,A2,A3,A4,A5',',')) 
        and 
        date1 between '2017-12-12' and '2018-05-08' 
        and grp = 1
        group by year(date1),datepart(week,date1)
        order by year(date1),[week]

iam 使用 ms sql-server 2016

需要帮助来修改它以满足我的需要,因为我没有想法 atm。

标签: sql-server-2016

解决方案


推荐阅读