Reputation: 3934
I have a big problem to find and next and previous records from current data. I have a data set which is below:
Need a result which is look like this below:
Is it possible? Could anyone help me?
Upvotes: 0
Views: 71
Reputation: 31889
You can use the LEAD
and LAG
window functions:
SELECT *,
PreviousShiftProfileID = LAG(ShiftProfileID) OVER(PARTITION BY EmployeeID ORDER BY CDate),
NextShiftProfileID = LEAD(ShiftProfileID) OVER(PARTITION BY EmployeeID ORDER BY CDate)
FROM yourTable
Upvotes: 2