在不创建任何扩展的情况下将我的列转换为 postgresql 中的行

Convert my columns in to rows in postgresql without creating any extensions

我有一个来自如下视图的数据结果,

但我想要这样的景色

任何人都可以帮助我通过 postgresql 在不使用扩展的情况下做到这一点。

使用聚合

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;

或者,您可以使用 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;