有這麼一張表,數據如下:
通過一條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