我有以下结果集
Status, Name
0, Type0
0, Type0
1, Type1
0, Type0
2, Type2
如何将类型的数量相加并使其看起来像
Type0,Type1,Type2
3,1,1
答案 0 :(得分:1)
SELECT
COUNT(CASE WHEN Name='Type0' THEN 1 END) AS Type0,
COUNT(CASE WHEN Name='Type1' THEN 1 END) AS Type1,
COUNT(CASE WHEN Name='Type2' THEN 1 END) AS Type2
FROM YourTable