最佳答案
您可以使用条件聚合:
select hk_district,
sum(complaint_no) filter (where month = '201801') as compaints_201801,
sum(complaint_no) filter (where month = '201802') as compaints_201802,
sum(complaint_no) filter (where month = '201803') as compaints_201803
from t
group by hk_district;
关于sql - 在 PostgreSQL 中创建数据透视表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53367503/