我希望避免null
值,并且在每个月没有月销售时获得零
SELECT * FROM
(
SELECT DATENAME(MONTH, doa) [Month], sum(1) [Sales Count]
From crime
GROUP BY YEAR(doa),DATENAME(MONTH, doa)
) AS MontlySalesData
PIVOT
(
sum([Sales Count]) FOR Month
IN
(
[January],[February],[March],[April],[May],[June],[July],
[August],[September],[October],[November],[December]
)
) AS MNamePivot