I have a table with position (junior, senior), salary, and an ID. I have done the following to find the highest salary for each position.
SELECT position, MAX(salary) FROM candidates GROUP BY position;
I want to transpose the outcome so that ‘junior’ and ‘senior’ are the columns without using crosstab. I have looked at many pivot examples but they are done on examples much more complex than mine.
3
Answers
Here is my attempt at teaching myself crosstab:
Edit: Below is no longer relevant as this appears to be PostgreSQL
Based on your description, it sounds like you probably want a pivot like this:
This example was made in SQL Server since we don’t know DBMS.
It depends on which SQL dialect you are running. It also depends on the complexity of your table. In SQL Server, I believe you can use the solutions provided in this question for relatively simple tables: Efficiently convert rows to columns in sql server
I am not proficient in PostgreSQL, but I believe there is a practical workaround solution since this is a simple table:
It worked with this example: