2

I have a data result from a view like below,

Current view

But I want a view like this

Need a view from the original view

Can any one help me to do this via postgresql without using extensions.

2
  • 1
    Please go through all the questions for pivot or crosstab Commented Dec 11, 2019 at 7:52
  • 1
    This is typically much better done in the application, than in SQL Commented Dec 11, 2019 at 7:53

1 Answer 1

4

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:

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.