PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Estrazione e media dei valori istantanei nel DB temporale in postgresql

select
    extract(hour from t1.dt) as hour,
    t1.dt as t1, t0.dt as t0,
    round(((t0.ambtemp + t1.ambtemp) / 2)::numeric, 2) as average
from
    n25 t0
    inner join
    n25 t1 on
        date_trunc('minute', t0.dt + interval '1 hour - 2 minutes')
        = date_trunc('minute', t1.dt)
where extract(minute from t1.dt) = 41
order by t1.dt

SQL Fiddle