+-----------+----------------------+-----------------------+-----------------------+
| review_id | old_group | new_group | desired_result |
+-----------+----------------------+-----------------------+-----------------------+
| 1 | null | null | BATCH |
| 2 | null | null | BATCH |
| 3 | BATCH | LEVEL_1 | LEVEL_1 |
| 4 | null | null | LEVEL_1 |
| 5 | LEVEL_1 | LEVEL_2 | LEVEL_2 |
| 6 | LEVEL_2 | L3 | LEVEL_3 |
| 7 | null | null | LEVEL_3 |
| 8 | null | null | LEVEL_3 |
| 9 | null | null | LEVEL_3 |
+-----------+----------------------+-----------------------+-----------------------+
I am working in snowflake and need to write a SQL query that based one new_group and old_group will create a new column filling in the blanks Each review is assigned a new and old group, I need to combine those values in order to have a separate column that would show specific review group on that review.
I've tried FIRST_VALUE(new_group IGNORE NULLS) OVER (ORDER BY review_id ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) but, it does not provide the right result: the last reviews are null as there is no upcoming group and the reviews are a bit shifted.