sql >> Base de Datos >  >> RDS >> Oracle

Cómo distribuir el promedio entre dos intervalos en Oracle

EDITAR:unión agregada para incluir la última fila faltante

Algo como esto puede funcionar. Suponiendo que los datos de entrada están en la tabla 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