select
city
,count(case when gender = 'm' then 1 else null end) as m_count
,count(case when gender <> 'm' then 1 else null end) as f_count
from table_name
group by city
select city, sum(male),sum(female) from
(select city ,count(gender) as male,0 as female from temp where gender='M' group by city
union
select city , 0,count(gender) as female from temp where gender='F'group by city)
group by city;
3条答案
按热度按时间elcex8rz1#
请尝试:
结果:
Demo
gwo2fgha2#
数据库服务器:
结果:
cbjzeqam3#