我有这个 MS SQL 2005 查询:
SELECT
DATEDIFF(dd, getdate(), CreatedOn) as Day,
COUNT(CreatedOn) as 'Active Cases'
FROM
[dbo].[IncidentBase]
WHERE
(StatusCode != 6 AND StatusCode != 5)
AND (CaseTypeCode = '200000' OR CaseTypeCode = '200005' OR CaseTypeCode = '200006')
GROUP BY
DATEDIFF(dd, getdate(), CreatedOn)
ORDER BY
Day DESC
并返回如下内容:
-1 10
-2 6
-5 4
-7 8
我真的希望它是这样的:
-1 10
-2 6
-3 0
-4 0
-5 4
-6 0
-7 8
(在没有记录的日期之间插入零)
我怎样才能做到这一点?
提前谢谢了!