在postgresql中将中的列转换为行,而不创建任何扩展

在postgresql中将中的列转换为行,而不创建任何扩展,sql,postgresql,pivot,crosstab,Sql,Postgresql,Pivot,Crosstab,我有一个来自如下视图的数据结果 但我想要这样的景色 有人能帮我通过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 gr

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

但我想要这样的景色

有人能帮我通过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;

请通读所有问题,因为这通常在应用程序中比在SQL中做得更好