Reputation: 11639
I have records that look like this:
I am trying to backfill every null with the value in the effective_date column that is 1 row ahead. So for the first null, the value should be: 2022-09-05 02:32:29.940416
. How can I do this?
this is on redshift.
Upvotes: 0
Views: 352
Reputation: 534
IIF(expiry_date IS NULL, LAG(effective_date, 1) OVER (ORDER BY effective_date DESC), expiry_date)
If effective_date is not consecutive throughout your dataset, then you would need to create an index column.
IIF(expiry_date IS NULL, LAG(effective_date, 1) OVER (ORDER BY idx_col DESC), expiry_date)
Upvotes: 1