Si j'ai bien compris, vous pouvez faire quelque chose comme ceci :
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');
Alternativement, vous pouvez utiliser 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;