我在下面有这个查询:
SELECT ied.[Reference]
,Count(*) AS 'Hits'
FROM dbo.ItemExportDefinition ied WITH (NOLOCK)
LEFT JOIN dbo.[Hits] WH WITH (NOLOCK) ON ied.[Reference] COLLATE DATABASE_DEFAULT = CASE
WHEN CHARINDEX('&', WH.QUERY, 0) = 0
THEN SUBSTRING(WH.QUERY, 4, 30)
WHEN CHARINDEX('&', WH.QUERY, 0) > 0
THEN SUBSTRING(SUBSTRING(WH.QUERY, 0, CHARINDEX('&', WH.QUERY)), 4, 100)
ELSE WH.QUERY
END
GROUP BY ied.[Guide Web Reference]
ORDER BY Hits DESC
它返回以下值:
ESC7730AE5 273697
ES4904A3EA 152392
ES0C69E6B9 11829
ES2413515E 5653
ESBA042518 1144
ES193DFEC8 1067
ESBF086D49 77
ES0AA87194 25
ESIXVY6881 9
ESE77AEF31 4
ES4087624D 3
ESF8BD9328 2
我想要的是我想得到计数为0的结果。例如,它看起来像这样:
ESC7730AE5 273697
ES4904A3EA 152392
ES0C69E6B9 11829
ES2413515E 5653
ESBA042518 1144
ES193DFEC8 1067
ESBF086D49 77
ES0AA87194 25
ESIXVY6881 9
ESE77AEF31 4
ES4087624D 3
ESF8BD9328 2
ESF8BD9328A 0
ESF8BD932832 0
ESF8BD932888 0
感谢。
答案 0 :(得分:0)
更改
Count(*) AS 'Hits'
在
Count(WH.QUERY) AS 'Hits'
Count(*)计算所有行,Count() - 计数值(NULL除外)