以下是我生成 Pivoted 结果的查询:
SELECT '# of Corrective Actions open and overdue' as [Corrective Actions breakdown],
[405],
[2865],
[3142],
[405]+[2865]+[3142] as [Total]
FROM
(Select il.Locationid , ca.CorrectiveActionsid, il.locOrder, ca.isDeleted caDeleted, i.isDeleted iDeleted, i.CompanyId companyid,ca.CADateBy, ca.Status from IncidentLocation il inner join incident i on il.IncidentId = i.IncidentId
inner join CorrectiveActions ca on i.IncidentId = ca.IncidentId
) AS SourceTable
PIVOT
(
COUNT(CorrectiveActionsid)
FOR LocationId IN ([405],[2865],[3142])
) PivotTable
where locOrder = 0 and caDeleted =0 and iDeleted = 0 and companyId = 210
and CADateBy <= '2013-01-01' and [Status] = 'Open'
我在考虑计数应该返回的空白数据。但我根本没有得到任何结果。请指导我做错了什么以及我应该怎么做才能使所有计数值为零而不是空白。