Jeśli chcesz różnicę z created_time
który nie ma komponentu czasowego, wtedy potrzebujesz takiej logiki:
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;
Zwraca wynik jako ułamki dnia.