I have the following sample data in an Oracle table (tab1) and I am trying to convert rows to columns. With pivot table I am able to have person_id like intended but in columns I can only achieve to have every job_id in different column and salary in rows. Is it possible to get it in form I need?
Sample data:
| person_id | job_id | salary |
|---|---|---|
| 1 | 50 | 100 |
| 1 | 51 | 125 |
| 2 | 51 | 115 |
| 2 | 54 | 105 |
| 2 | 55 | 80 |
My intended output:
| person_id | job_1 | salary_1 | job_2 | salary_2 | job_3 | salary_3 |
|---|---|---|---|---|---|---|
| 1 | 50 | 100 | 51 | 125 | null | null |
| 2 | 51 | 115 | 54 | 105 | 55 | 80 |
I tried to use pivot somehow as here I found similar problems: https://stewashton.wordpress.com/2018/05/28/generic-pivot-function/
Using pivot on multiple columns of an Oracle row
As It is not exaclty the same I'm stuck trying by trial and error as well as searching google for simillar question but I cannot find any.
SQL Pivot on multiple columns with INT and NVARCHAR datatypes - best answer here could help me but I can't have every job_id in different column as there is around 1000 different jobs and every person has 2-5 jobs. It means that I can have 5*2+1 columns at max.
I am using oracle 19 if it matters.