1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| with data as
(
select 'A' as id, 1 as num, 120 as val from dual union all
select 'A' , 2 , null from dual union all
select 'A' , 3 , 100 from dual union all
select 'A' , 4 , null from dual union all
select 'B' , 1 , null from dual union all
select 'B' , 2 , 200 from dual union all
select 'B' , 3 , null from dual union all
select 'B' , 4 , null from dual
)
select id, num, val,
max (val) over (partition by id order by num asc) as val_max,
last_value(val IGNORE NULLS) over (partition by id order by num asc) as val_last
FROM DATA
ORDER BY id asc, num asc;
ID NUM VAL VAL_MAX VAL_LAST
-- ---------- ---------- ---------- ----------
A 1 120 120 120
A 2 120 120
A 3 100 120 100 -- Problème ici avec max !
A 4 120 100
B 1
B 2 200 200 200
B 3 200 200
B 4 200 200 |
Partager