zoukankan      html  css  js  c++  java
  • 《SQL 进阶教程》 case:练习题1-1-2 转换行列——在表头里加入汇总列

    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

  • 相关阅读:
    BD String
    1114
    1083
    1084
    1108
    1087
    1145
    1217
    1164
    反射
  • 原文地址:https://www.cnblogs.com/newlangwen/p/10565710.html
Copyright © 2011-2022 走看看