Обновлено после уточнения
Match_recognize обычно работает быстрее, чем старое решение start_of_group, основанное на аналитических c функциях:
select *
from your_tab
match_recognize (
order by Change_Date
measures
first(Change_Date) as Change_Date,
first(Market_Intro_Date) as Market_Intro_Date,
first(Author ) as Author
pattern (A B*)
define
b as Market_Intro_Date = prev(Market_Intro_Date) and Change_Date>prev(Change_Date)
)
order by 1;
Full пример с вашими тестовыми данными:
with your_tab(Market_Intro_Date, Change_Date, Author) as (
select to_date('01.06.2025','dd.mm.yyyy'), to_date('10.07.2020','dd.mm.yyyy'), 'Meyer ' from dual union all
select to_date('01.01.2025','dd.mm.yyyy'), to_date('30.06.2020','dd.mm.yyyy'), 'Harrin ' from dual union all
select to_date('01.01.2025','dd.mm.yyyy'), to_date('01.05.2020','dd.mm.yyyy'), 'Floyd ' from dual union all
select to_date('01.01.2025','dd.mm.yyyy'), to_date('15.04.2020','dd.mm.yyyy'), 'Peterson' from dual union all
select to_date('01.12.2024','dd.mm.yyyy'), to_date('20.03.2020','dd.mm.yyyy'), 'George ' from dual union all
select to_date('01.12.2024','dd.mm.yyyy'), to_date('10.03.2020','dd.mm.yyyy'), 'Smith ' from dual union all
select to_date('01.12.2024','dd.mm.yyyy'), to_date('15.01.2020','dd.mm.yyyy'), 'George ' from dual union all
select to_date('01.01.2025','dd.mm.yyyy'), to_date('15.12.2019','dd.mm.yyyy'), 'Lee ' from dual union all
select to_date('01.01.2025','dd.mm.yyyy'), to_date('01.11.2019','dd.mm.yyyy'), 'Alfonso ' from dual union all
select to_date('01.01.2025','dd.mm.yyyy'), to_date('10.10.2019','dd.mm.yyyy'), 'Peterson' from dual union all
select to_date('01.07.2025','dd.mm.yyyy'), to_date('30.09.2019','dd.mm.yyyy'), 'Smith ' from dual union all
select to_date('01.07.2024','dd.mm.yyyy'), to_date('20.09.2019','dd.mm.yyyy'), 'Lee ' from dual union all
select to_date('01.07.2024','dd.mm.yyyy'), to_date('10.09.2019','dd.mm.yyyy'), 'Meyer ' from dual union all
select to_date('01.07.2024','dd.mm.yyyy'), to_date('01.05.2019','dd.mm.yyyy'), 'Smith ' from dual
)
select *
from your_tab
match_recognize (
order by Change_Date
measures
first(Change_Date) as Change_Date,
first(Market_Intro_Date) as Market_Intro_Date,
first(Author ) as Author
pattern (A B*)
define
b as Market_Intro_Date = prev(Market_Intro_Date) and Change_Date>prev(Change_Date)
)
order by 1;
CHANGE_DATE MARKET_INTRO_DATE AUTHOR
------------------- ------------------- --------
2019-05-01 00:00:00 2024-07-01 00:00:00 Smith
2019-09-30 00:00:00 2025-07-01 00:00:00 Smith
2019-10-10 00:00:00 2025-01-01 00:00:00 Peterson
2020-01-15 00:00:00 2024-12-01 00:00:00 George
2020-04-15 00:00:00 2025-01-01 00:00:00 Peterson
2020-07-10 00:00:00 2025-06-01 00:00:00 Meyer