我的表PlazaInsuranceWPDataSet
有列WrittenPremium和SICCode。列SICCode具有NULL
个值。
总数WrittenPremium
为108,515,689。
所以,如果我说:
select sum(WrittenPremium)
from PlazaInsuranceWPDataSet
结果是正确的。
但如果我说
select sum(WrittenPremium)
from PlazaInsuranceWPDataSet
WHERE SICCode IN ('0161','0173','0179','0181'...)
结果是108,024,995这是不正确的,因为它没有选择SICCode
值NULL
。
我尝试过使用ISNULL功能,但仍然没有成功:
select sum(WrittenPremium)
from PlazaInsuranceWPDataSet
WHERE ISNULL(SICCode,0) IN ('0161','0173','0179','0181'...)
那么如何使用sum
条款获取WrittenPremium
where
的全部内容?
答案 0 :(得分:2)
WHERE SICCode IN ('0161','0173','0179','0181'...)
OR SICCode is null
答案 1 :(得分:1)
请试一试。
选择总和(WrittenPremium) 来自PlazaInsuranceWPDataSet WHERE ISNULL(SICCode,0)IN('0','0161','0173','0179','0181'...)
此致
阿都
答案 2 :(得分:0)
您可以将值包装在合并中。
选择sum(coalesce(WrittenPremium,0)) 来自PlazaInsuranceWPDataSet WHERE ISNULL(SICCode,0)IN('0161','0173','0179','0181'...)