Вы можете использовать first_value
функцию с between 3 following and unbounded following
предложением окон:
with t(col1,col2,col3,col4) as
(
select 'A', 'A1', .3, 'Pramisse 1' from dual union all
select 'A', 'A1', .3, 'Pramisse 2' from dual union all
select 'A', 'A1', .3, 'Pramisse 3' from dual union all
select 'A', 'A1', .3, 'Pramisse 4' from dual union all
select 'A', 'A2', 1, 'Pramisse 1' from dual union all
select 'A', 'A2', 1, 'Pramisse 2' from dual union all
select 'A', 'A2', 1, 'Pramisse 3' from dual union all
select 'A', 'A2', 1, 'Pramisse 4' from dual union all
select 'A', 'A3', 1, 'Pramisse 1' from dual union all
select 'A', 'A3', 1, 'Pramisse 2' from dual union all
select 'A', 'A3', 1, 'Pramisse 3' from dual union all
select 'A', 'A3', 1, 'Pramisse 4' from dual
)
select first_value(col1) over
( partition by col2 order by col4 rows
between 3 following and unbounded following ) as col1,
first_value(col2) over
( partition by col2 order by col2 rows
between 3 following and unbounded following ) as col2,
first_value(col3) over
( partition by col2 order by col4 rows
between 3 following and unbounded following ) as col3,
col4
from t;
COL1 COL2 COL3 COL4
---- ---- ----- ----------
A A1 0,30 Pramisse 1
Pramisse 2
Pramisse 3
Pramisse 4
A A2 1 Pramisse 1
Pramisse 2
Pramisse 3
Pramisse 4
A A3 1 Pramisse 1
Pramisse 2
Pramisse 3
Pramisse 4
Демо