Microsoft - FROM - 使用 PIVOT 和 UNPIVOT
How to replace (null) values with 0 output in PIVOT
在使用PIVOT時
SELECT CLASS, [AZ], [CA], [TX] FROM #TEMP PIVOT (SUM(DATA) FOR STATE IN ([AZ], [CA], [TX])) AS PVT ORDER BY CLASS加入isnull在父查詢SELECT的位置上即可
SELECT CLASS, isnull([AZ],0), isnull([CA],0), isnull([TX],0) FROM #TEMP PIVOT (SUM(DATA) FOR STATE IN ([AZ], [CA], [TX])) AS PVT ORDER BY CLASS
沒有留言:
張貼留言