I have a table as similar to below and
1. I would need to update the CASE_ IN when there is a null then I must update it with previous non-null value.
Will this below SQL work?
last_value(case_in ignore nulls) over (partition by ID order by date rows unbounded preceding)
2. Next, I need to update the BR_CD. any values between 0-100 and NULL are invalid hence those needs to be updated to last previous BR_CD. How do I achieve this, please can you help? I have given the sample input and output.
Solved! Go to Solution.
The LAST_VALUE should return what you want and for the 2nd case you simply modify it to:
last_value(case when case_in not between 0 and 100 then case_in end ignore nulls) over (partition by ID order by date rows unbounded preceding)
should it be br_cd? because I need to update the br_Cd based on case_in
last_value(case when case_in not between 0 and 100 then br_cd end ignore nulls) over (partition by ID order by date rows unbounded preceding)