2016-12-07 121 views

回答

2

使用樞軸查詢:

SELECT catID, 
     SUM(CASE WHEN scStatus = 0 THEN 1 ELSE 0 END) AS [0], 
     SUM(CASE WHEN scStatus = 2 THEN 1 ELSE 0 END) AS [2], 
     SUM(CASE WHEN scStatus = 3 THEN 1 ELSE 0 END) AS [3] 
FROM Category 
GROUP BY catID 
+1

感謝ü非常.... –

1

操作

select  * 
from  (select catID,scStatusvalue from t) t 
       pivot (count(scStatusvalue) for scStatusvalue in ([0],[2],[3])) t 
+0

謝謝ü非常.... –

相關問題