[英]Convert my columns in to rows in postgresql without creating any extensions
use aggregation使用聚合
select project, max(case when role='owner' then name end) as owner,
max(case when role='client' then name end) as client,
max(case when role='Team' then name end) as Team
from table
group by project;
Alternatively you can use the filter()
clause which makes this a bit easier to read:或者,您可以使用
filter()
子句,这使它更容易阅读:
select project,
max(name) filter (where role='owner') as owner,
max(name) filter (where role='client') as client,
max(name) filter (where role='Team') as Team
from table
group by project;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.