I've been trying to created a query that repeats last row result when current row is null, e.g.:
Here is my data:
A1 | B2
--------------
1 | 2
2 | 1
3 | (null)
4 | (null)
5 | 3
So I want that to be:
A1 | B2
--------------
1 | 2
2 | 1
3 | 1
4 | 1
5 | 3
When the value is null, I want to fill with the last row result. I tried:
SELECT A1, COALESCE (B2, Last_Value (B2) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING)) AS B2 FROM
(SELECT 1 AS A1, 2 AS B2
UNION ALL
SELECT 2, 1
UNION ALL
SELECT 3, NULL
UNION ALL
SELECT 4, NULL
UNION ALL
SELECT 5, 3) TAB
But the result is:
A1 | B2
--------------
1 | 2
2 | 1
3 | 1
4 | (null)
5 | 3
Anyone knows how to do this?
Thanks,