Skip to content
Advertisement

Creating new category columns with corresponding values from a SELECT statement

I’m trying to create a SELECT statement where the values under “category” and “category2” column will become actual columns and show the corresponding “url” and “url2” under them.

Basically I have the following table:

…and I want the end result to look like this:

Any ideas? I don’t know which options to even look for? I’m using PostgreSQL.

Demo v3

Advertisement

Answer

For these 3 categories you can use conditional aggregation:

See the demo.
Results:


Edit

See the demo.
Results:

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