select
case when sex = 1 then '男性' else '女性' end as '性别',
sum(case when name='哈尔滨' THEN population else 0 end) as '哈尔滨',
sum(case when name='大庆' then population else 0 end) as '大庆',
sum(case when name='齐齐哈尔' then population else 0 end) as '齐齐哈尔',
sum(case when name='长春' then population else 0 end) as '长春',
sum(case when name='吉林' then population else 0 end) as '吉林',
sum(case when name ='哈尔滨' or name ='大庆' or name ='齐齐哈尔' then population else 0 end) as '黑龙江',
sum(population) as 总计
from city_population_copy
GROUP BY sex
转载于:https://www.cnblogs.com/newlangwen/p/10565710.html