Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Como distribuir a média entre dois intervalos no oracle


EDIT:Adicionado união para incluir a linha final ausente

Algo assim pode funcionar. Supondo que os dados de entrada estejam na tabela 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