Anda ingin menghapus setiap baris di mana baris sebelumnya memiliki jenis yang sama. Jadi:
select timestamp, type
from (select t.*,
lag(type) over (order by timestamp) as prev_type
from ticket_events t
) t
where prev_type <> type or prev_type is null;
where
klausa juga dapat diutarakan sebagai:
where prev_type is distinct from type
Jika Anda ingin menghapus baris "yang menyinggung", Anda dapat melakukan hal berikut -- dengan asumsi bahwa timestamp
unik:
delete from ticket_events
using (select t.*,
lag(type) over (order by timestamp) as prev_type
from ticket_events t
) tt
where tt.timestamp = t.timestamp and
tt.prev_type = t.type;