我有一个查询,我在其中计算任何给定客户每月的不同索赔数量,以获得 YTD 报告。但我发现如果客户在这一年没有任何索赔(所以每个月都应该显示为 0),那么客户根本不会出现在结果集中。我需要客户显示该月的计数为“0”。有谁知道如何做到这一点?感谢您的帮助!:)
我的查询类似于:
Select c.client_name,
SUM(CASE DATEPART(MONTH,c2.DateField)WHEN 1 THEN 1 ELSE 0 END) AS [Jan-13],
SUM(CASE DATEPART(MONTH,c2.DateField)WHEN 2 THEN 1 ELSE 0 END) AS [Feb-13],
SUM(CASE DATEPART(MONTH,c2.DateField)WHEN 3 THEN 1 ELSE 0 END) AS [Mar-13] etc.....
From Client c (Nolock)
inner join claim c2 (nolock)
on c.client_id = c2.client_id
Where c.client_id IN (1,3,4,5,7) AND
c2.DateField between '001-01-2013' and Getdate()
GROUP BY c.client_name
ORDER BY c.Client_name
我的结果如下:
Client Name|Jan-13|Feb-13|Mar-13|etc.....
abc company|12 |17 |0 |etc......
zzz company|3 |0 |15 |etc...
我需要结果看起来像:
Client Name|Jan-13|Feb-13|Mar-13|etc.....
abc company|12 |17 |0 |etc......
rad company|0 |0 |0 |etc.....
zzz company|3 |0 |15 |etc...