На основе столбца [Employee Details]
вы можете добавить СОСТОЯНИЕ АГРЕГАЦИИ.
Я создал образец таблицы ниже и попытался получить ожидаемый результат.
Таблица: Сотрудники
WORKER | TRANSDATE | EMPLCHANGETYPE | EmployeeDetails
5637158890 | 28/06/2018 | 5 | TL
5637158890 | 28/06/2018 | 3 | HR
5637158890 | 28/06/2018 | 9 | Gurgaon
5637158890 | 28/06/2018 | 6 | Ram
5637158890 | 28/06/2018 | 8 | Active
5637158890 | 28/06/2018 | 4 | TL
5637158890 | 06/08/2018 | 6 | Ravi
5637158890 | 03/12/2018 | 9 | Gurgaon
5637158890 | 03/12/2018 | 6 | Sam
5637158890 | 05/04/2019 | 8 | Inactive
Запрос
SELECT
WORKER,
TRANSDATE,
Max(case when row_no=1 then Employeedetails end )as EmpDetails_1,
Max(case when row_no=2 then Employeedetails end )as EmpDetails_2,
Max(case when row_no=3 then Employeedetails end )as EmpDetails_3,
Max(case when row_no=4 then Employeedetails end )as EmpDetails_4
FROM
(
SELECT WORKER,TRANSDATE,Employeedetails,
ROW_NUMBER() OVER(PARTITION BY WORKER,TRANSDATE order by WORKER,TRANSDATE Desc) as row_no
FROM Employees
)
as EmployeesNew
group By WORKER,TRANSDATE
Выход:
WORKER |TRANSDATE |EmpDetails_1|EmpDetails_2|EmpDetails_3|EmpDetails_4
5637158890 |03/12/2018 |Gurgaon | Sam |(null) |(null)
5637158890 |05/04/2019 |Inactive | (null) |(null) |(null)
5637158890 |06/08/2018 |Ravi | (null) |(null) |(null)
5637158890 |28/06/2018 |TL | HR |Gurgaon |Ram