I’ve used the following SQL query to pull out the following data:
Select
Employee_Department, Employee_ID, DateTime_From, Wage_From, DateTime_To, Wage_To
From
wage_tbl
Where
Employee_ID = 254 or
Employee_ID = 103 or
Employee_ID = 256
The following is the result of the query:
Employee_Department | Employee_ID | DateTime_From | Wage_From | DateTime_To | Wage_To |
---|---|---|---|---|---|
Sales | 254 | 11-Jun-2022 05:20:00 | 10 | 11-Jun-2022 07:20:00 | 15 |
Sales | 254 | 11-Jun-2022 07:20:00 | 15 | 11-Jun-2022 08:20:00 | 30 |
Sales | 254 | 11-Jun-2022 08:20:00 | 30 | 11-Jun-2022 09:20:00 | 15 |
Marketing | 103 | 11-Jun-2022 11:20:00 | 30 | 11-Jun-2022 12:20:00 | 60 |
Marketing | 103 | 11-Jun-2022 12:20:00 | 60 | 11-Jun-2022 14:20:00 | 100 |
Sales | 256 | 11-Jun-2022 10:20:00 | 20 | 11-Jun-2022 11:20:00 | 30 |
Sales | 256 | 11-Jun-2022 11:20:00 | 30 | 11-Jun-2022 13:20:00 | 35 |
I want to combine rows based on the Employee_ID column such that the table now becomes something like:
Employee_Department | Employee_ID | DateTime_1 | Wage_1 | DateTime_2 | Wage_2 | DateTime_3 | Wage_3 | DateTime_4 | Wage_4 |
---|---|---|---|---|---|---|---|---|---|
Sales | 254 | 11-Jun-2022 05:20:00 | 10 | 11-Jun-2022 07:20:00 | 15 | 11-Jun-2022 08:20:00 | 30 | 11-Jun-2022 09:20:00 | 15 |
Marketing | 103 | 11-Jun-2022 11:20:00 | 30 | 11-Jun-2022 12:20:00 | 60 | 11-Jun-2022 14:20:00 | 100 | null | null |
Sales | 256 | 11-Jun-2022 10:20:00 | 20 | 11-Jun-2022 11:20:00 | 30 | 11-Jun-2022 13:20:00 | 35 | null | null |
I have tried using Pivot but can't seem to figure out how to get the configuration that I want.
Can someone please help with this?