SQL >> Base de Datos >  >> RDS >> Oracle

Escribir una vista de Oracle que reste timestamps de distintas columnas

Si quieres la diferencia medida contra el created_time que no tiene componente de hora, entonces querrás una lógica del estilo de esta:

select msg_guid, (max(case when payload_type = 1 then created_time end) - (case when max(case when payload_type = 2 then created_time end) <> trunc(max(case when payload_type = 2 then created_time end)) then max(case when payload_type = 2 then created_time end) when max(case when payload_type = 3 then created_time end) <> trunc(max(case when payload_type = 3 then created_time end)) then max(case when payload_type = 3 then created_time end) end) ) as diff from table t group by msg_guid; 

Esto devuelve el resultado expresado como fracciones de un día. Si prefieres verlo en una unidad más legible, multiplica por 24 para obtener horas o envuelve la resta en numtodsinterval(diff, 'DAY').