Skip to content
Advertisement

Oracle SQL: Get the previous values

I have two columns table: Id, and value.

ID Value
1
2 AA
3
4 BB
5
6
7
8 CC
9

I need a query in Oracle to return the result as

ID Value
1
2 AA
3 AA
4 BB
5 BB
6 BB
7 BB
8 CC
9 CC

Is there anyway to do this? Thanks in advance.

Advertisement

Answer

select id, last_value(value IGNORE NULLS) over (order by id) as modified_value
from   your_table
;
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement