开发者

count the status types and put totals in one row

开发者 https://www.devze.com 2023-04-08 16:40 出处:网络
I have the following result set Status, Name 0, Type0 0, Type0 1, Type1 0, Type0 2, Type2 How do I sum the c开发者_JAVA技巧ounts of types and make it look like

I have the following result set

Status, Name
0, Type0
0, Type0
1, Type1
0, Type0
2, Type2

How do I sum the c开发者_JAVA技巧ounts of types and make it look like

Type0,Type1,Type2
3,1,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
0

精彩评论

暂无评论...
验证码 换一张
取 消