开发者

count the status types and put totals in one row

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜