如果不存在数据,则无法显示0值

时间:2019-05-07 06:37:37

标签: sql

我想显示所有数据,但是在某天没有输出  仍然显示数据,但是它是错误的。第二张照片上星期一和星期二的数据有误。值必须为0

select sum(Qtyinspect3k) as '3k', sum(Qtyinspect10k) as '10k', 
sum(QtyDefect) as 'reject' 
from dbo_OQAVMView 
whereYear like '2019' and WorkWeek between 'ww01' AND 'ww02' 
and Day = 'Saturday' and not exists ( select * from dbo_OQAVMView 
where LotNo is not null and Year is not null  )

Correct Output

Wrong and current Output

1 个答案:

答案 0 :(得分:0)

您可以使用case语句获取正确的输出。我无法很好地理解您的代码,因此无法给您提供完整的查询,但是此语法应该会有所帮助:

SELECT
    CASE 
        WHEN SUM(column) != NULL THEN SUM(column) 
        ELSE 0 
    END
FROM table

希望这会有所帮助:)