私の理解が正しければ、次のようなことができます:
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');
または、 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;