skip to Main Content

I’m new to SQL and I would like to to group by ID and create another column based on value.

Let me give an example:

Foreign ID Type Value
1 ‘X’ 10
1 ‘Y’ 20
2 ‘X’ 30
2 ‘Y’ 40

My expected output would be

Foreign ID X Y
1 10 20
2 30 40

2

Answers


  1. Grouping is done with Group By. And making a column out of a row, which is what the example shows is done with Crosstab function.

    Login or Signup to reply.
  2. I believe that a basic Left Join should do: https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-left-join/

    Also, write the code, it hepls.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search