简体   繁体   English

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

[英]Convert my columns in to rows in postgresql without creating any extensions

I have a data result from a view like below,我有如下视图的数据结果,

目前来看

But I want a view like this但我想要这样的景色

需要从原始视图中查看

Can any one help me to do this via postgresql without using extensions.任何人都可以在不使用扩展的情况下通过 postgresql 帮助我做到这一点。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM