简单的行列转化
有这么一张表,数据如下:
通过一条sql语句获得如下的展示效果:
这种就是行列转换,
sql为:
#sum(case when type='A' then money end) as A ,按国家分组后如果当前行的数据的类型是A,,则累积money金额,放在列字段A下作为值。
select country,sum(case when type='A' then money end) as A,sum(case when type='B' then money end) as B from areacount GROUP BY country