1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| create table demo as
with got_my_data(id, unite, date_deb, date_fin) as
(
select '003492', 'UNITE A', to_date('18/11/2021 12:41:00','dd/mm/yyyy hh24:mi:ss') ,to_date('18/11/2021 16:00:00', 'dd/mm/yyyy hh24:mi:ss') from dual union all
select '003492', 'UNITE A', to_date('18/11/2021 16:00:00','dd/mm/yyyy hh24:mi:ss') ,to_date('24/11/2021 10:25:00', 'dd/mm/yyyy hh24:mi:ss') from dual union all
select '003492', 'UNITE B', to_date('01/04/2022 14:56:00','dd/mm/yyyy hh24:mi:ss') ,to_date('02/04/2022 15:00:00', 'dd/mm/yyyy hh24:mi:ss') from dual union all
select '003492', 'UNITE B', to_date('02/04/2022 15:00:00','dd/mm/yyyy hh24:mi:ss') ,to_date('03/04/2022 20:20:00', 'dd/mm/yyyy hh24:mi:ss') from dual union all
select '014588', 'UNITE C', to_date('05/03/2019 15:13:00','dd/mm/yyyy hh24:mi:ss') ,to_date('05/03/2019 16:48:41', 'dd/mm/yyyy hh24:mi:ss') from dual union all
select '014588', 'UNITE C', to_date('05/03/2019 17:00:00','dd/mm/yyyy hh24:mi:ss') ,to_date('23/03/2019 10:00:00', 'dd/mm/yyyy hh24:mi:ss') from dual )
select * from got_my_data;
SELECT
id,
unite,
start_dat,
end_dat
FROM
demo
match_recognize
(
partition by id, unite
order by date_deb
measures
first(date_deb) as start_dat,
last(date_fin) as end_dat
one row per match
pattern (a x* )
define
x as date_deb = prev(date_fin)
)
ORDER BY
id, unite;
ID UNITE START_DAT END_DAT
------ ------- ------------------- -------------------
003492 UNITE A 18/11/2021 12:41:00 24/11/2021 10:25:00
003492 UNITE B 01/04/2022 14:56:00 03/04/2022 20:20:00
014588 UNITE C 05/03/2019 15:13:00 05/03/2019 16:48:41
014588 UNITE C 05/03/2019 17:00:00 23/03/2019 10:00:00 |