В Oracle 12.1 или выше, MATCH_RECOGNIZE может выполнять быструю работу с такими назначениями.Предложение WITH предназначено только для предоставления тестовых данных (удалите их, прежде чем пытаться найти решение).
with
test_data(id, account, status) as (
select 1, 'X', 'A' from dual union all
select 2, 'Y', 'C' from dual union all
select 3, 'Y', 'A' from dual union all
select 4, 'X', 'B' from dual union all
select 5, 'X', 'C' from dual union all
select 6, 'Y', 'C' from dual union all
select 7, 'X', 'A' from dual union all
select 8, 'X', 'C' from dual union all
select 9, 'X', 'C' from dual
)
select id, account, status
from test_data
match_recognize(
partition by account
order by id
all rows per match
pattern ( A X? )
define A as status = 'A',
X as status is null or status != 'A'
)
order by id -- if needed
24 ;
ID ACCOUNT STATUS
---------- ------- -------
1 X A
3 Y A
4 X B
6 Y C
7 X A
8 X C
6 rows selected.