Oracle: pobranie poprzedniego i następnego wpisu

with test as (
select 1 id ,2 ext_id, 1 wartosc from dual union all
select 2 id ,2 ext_id, 2 wartosc from dual union all
select 3 id,2 ext_id, 3 wartosc from dual union all
select 4 id,1 ext_id, 4 wartosc from dual
)

select id, wartosc,
lag(wartosc) over (partition by ext_id order by id) as poprzednie,
lead(wartosc) over (partition by ext_id order by id) as nastepne
from test
order by id;