Skip to content
Advertisement

Postgres transpose a row

I have a table which looks like the following :-

I want to transpose it to the following form, in Postgres:

I know I’m supposed to use the pivot operation to do this, but I can’t figure out the right syntax to get this done.

Any help to get this done will be appreciated.

Advertisement

Answer

That would simply be:

but with multiple rows in the table you don’t see anymore, which a is related to which b, etc. So while this matches your request, you may want to think over, whether this is really what you want to do.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement