Oracle
 sql >> Database >  >> RDS >> Oracle

Come distribuire la media tra due intervalli in Oracle

EDIT:aggiunta unione per includere l'ultima riga mancante

Qualcosa del genere potrebbe funzionare. Supponendo che i dati di input siano nella tabella a,

with b as
(select level-1 lev
from dual
connect by level <= 60
),
v as
(
select start_date, value current_value, lead(value) over (order by start_date) next_value
from a
)
select start_date+ (lev)/(24*60), (current_value*((60-(b.lev))/60) + next_value*(b.lev)/60) avg_value
from v, b
where v.next_value is not null
union
select start_date, current_value
from v
where v.next_value is null
order by 1