数据表结构

company_name

varchar

value

int4/numeric

type

varchar

 

表数据

company_name

value

type

公司A

101

A用地亩

公司A

102

B税收万元

公司A

103

C能耗吨煤

 

sql

select company_name,
sum(case when type='A用地亩' then value else 0 end) as "用地亩",
sum(case when type='B税收万元' then value else 0 end) as "税收万元",
sum(case when type='C能耗吨煤' then value else 0 end) as "能耗吨煤"
from temp
group by company

结果:

company_name

用地亩

税收万元

能耗吨煤

公司A

101

102

103