Se ho capito bene, puoi fare qualcosa del genere:
select count(*)
from (select listagg(flag) within group (order by dt) as flags
from temp
) x
where not regexp_like(flags, 'HH|EE|HS|SE');
In alternativa, puoi usare lag()
:
select (case when count(*) = sum(case when flag2 not in ('HH', 'EE', 'HS', 'SE')
then 1 else 0
end) as return_value
from (select t.*,
(lag(flag) over (order by dt) || flag) as flag2
from temp
) t;