Reputation: 331
I have the following query:
SELECT
EEEV_EMPL_ID,
EEEV_DT,
EEEV_CCTR_ID,
LAG(EEEV_CCTR_ID, 1, ' ') OVER(ORDER BY EEEV_EMPL_ID DESC, EEEV_END_DT ASC) AS prev
FROM
CDAS.VDWHEEEV1 eeev1
ORDER BY
EEEV_EMPL_ID
So the table can have multiple rows for each EEEV_EMPL_ID. I want to lag for each group of unique empl_id's. I dont want to lag from one empl_id to another. So if it is the last row of the group, the lag value should be Null or something. Right now it is just lagging to the next row, even if it is a different empl_id. How do I accomplish that. I hope that makes sense.
Upvotes: 0
Views: 483
Reputation: 1271003
If I understand correctly, you want partition by
:
LAG(EEEV_CCTR_ID, 1, ' ') OVER (PARTITION BY EEEV_EMPL_ID ORDER BY EEEV_END_DT ASC) AS prev
Upvotes: 2