Reputation: 163
I need to aggregate few rows, but unfortunately not all.
What I currently have:
select type,count(*) from world group by type;
Type | count(*)
---------------
Man | 10
Woman | 20
Dog | 2
Cat | 1
Turtle | 2
And I need to format this query to obtain such table
Type | count(*)
---------------
Man | 10
Woman | 20
Animals | 5
Is it doable by one query?
Upvotes: 0
Views: 52
Reputation: 50163
You can do :
select (case when type not in ('man', 'women')
then 'Animals'
else type
end), count(*)
from world
group by (case when type not in ('man', 'women')
then 'Animals'
else type
end);
Upvotes: 4