Rod
Rod

Reputation: 15433

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 counts of types and make it look like

Type0,Type1,Type2
3,1,1

Upvotes: 2

Views: 75

Answers (1)

Martin Smith
Martin Smith

Reputation: 452978

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

Upvotes: 1

Related Questions