I am having some trouble making a pivot in oracle sql. I have a table with workdate
, employee
and their shift
for a day. This table is called SHIFT
.
I want that in this pivot, the workdate becomes the column headings, the employee become the row headings and the shifts be the day so you can see the employee shift per day.
My current problem is that i have a query but the pivot requires that i put an aggregate function. The query is as follows:
select employee, workdate, shift from shift
pivot (
max(shift)
for employee
in (
1,2,3,4
)
)
SO i did this and it is bringing back all the columns and not in a pivoted format. Current Strucutre:
employee | workdate | shift |
---|---|---|
employee1 | date1 | shift1 |
employee1 | date2 | shift2 |
employee2 | date1 | shift1 |
employee2 | date2 | shift2 |
employee3 | date1 | shift1 |
employee3 | date2 | shift2 |
employee4 | date1 | shift1 |
employee4 | date2 | shift2 |
employee5 | date1 | shift1 |
employee5 | date2 | shift2 |
My desired results are:
date1 | date2 | date3 | |
---|---|---|---|
employee1 | shift1 | shift2 | shift3 |
employee2 | shift1 | shift2 | shift3 |
employee3 | shift1 | shift2 | shift3 |
employee4 | shift1 | shift2 | shift3 |
Thanks you for your answers.