我正在运行同一查询的多个实例。下面的版本不应该返回任何数据,但我在每一列中都得到 1 行“null”:
SELECT (CASE ScanName WHEN 'SYSTEM-HQ' THEN 'HQ
System' END) AS System,
sum(CASE pspplMSSeverity WHEN 1 THEN 10 WHEN 2 THEN 9 WHEN
3 THEN 6 WHEN 4 THEN 3 END) AS Score,
(sum(CASE pspplMSSeverity WHEN 1 THEN 10 WHEN 2 THEN 9
WHEN 3 THEN 6 WHEN 4 THEN 3 END)/COUNT(pspplMSSeverity)) AS
Grade
FROM missingpatches
WHERE ScanName like '%SYSTEM-HQ%'
ORDER BY LAST_UPDATE DESC LIMIT 1
如何修改此查询以确保仅在存在有效值时才返回数据?
这可能是由于在导致返回 Null 数据的主 SQL 语句中使用了 Case 和 Sum?