Du vil fjerne enhver række, hvor den forrige række har samme type. Så:
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 prev_type is distinct from type
Hvis du vil slette de "fornærmende" rækker, kan du gøre følgende -- forudsat at tidsstempel
er 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;