我需要汇总几行,但不幸的是,不是全部。
我目前拥有的东西:
select type,count(*) from world group by type;
Type | count(*)
---------------
Man | 10
Woman | 20
Dog | 2
Cat | 1
Turtle | 2
我需要格式化此查询以获取此类表
Type | count(*)
---------------
Man | 10
Woman | 20
Animals | 5
一个查询是否可行?
答案 0 :(得分:4)
您可以:
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);