This is my table with values
id category
A Apple
A NULL
A Apple
B NULL
B Pear
B Pear
B Peach
B NULL
B NULL
C NULL
C NULL
C Apple
This is what I want my table to be
id category
A Apple
A Apple
A Apple
B NULL
B Pear
B Pear
B Peach
B Peach
B Peach
C NULL
C NULL
C Apple
These are the rules that I want to apply;
- If category is null, then fill it in with the most recent category (for that id)
- If there is no value for category above for that id, then remain null
We can imagine that there's a third column called date and that's what the data is sorted on
I tried to use first_value() but I just got nulls for the category column
I'm using SQL on a Snowflake instance