Вася А
Петя Б
Вася Б
Женя А
Петя Б
Вася Б
Женя А
Петя А
Петя Б
Вася Б
with s as (
select
* ,
row_number() over (partition by name order by event_time asc) -
row_number() over (partition by name, event order by event_time asc) gr
from t
) select
name, event, count(*)
from s
group by name, event, gr
order by count desc
limit 1;