有这么一张表,数据如下:

简单的行列转化

通过一条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

相关文章:

  • 2021-07-19
  • 2021-11-15
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2021-08-12
  • 2021-06-19
  • 2021-07-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2022-02-05
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
相关资源
相似解决方案