数据表结构
| 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 |

本文介绍了如何使用SQL查询公司A的数据表,通过类型过滤计算不同类型的数值总和,包括用地亩数、税收和能耗。
22万+

被折叠的 条评论
为什么被折叠?



