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
| with data as (
select 'Toto Tata' as name, to_date ('25/08/2020 00:00:00','dd/mm/yyyy hh24:mi:ss') as DATERDV, 'Site B' as NOM from dual union all
select 'Toto Tata', to_date ('26/08/2020 00:00:00','dd/mm/yyyy hh24:mi:ss'), 'Site B' from dual union all
select 'Toto Tata', to_date ('27/08/2020 00:00:00','dd/mm/yyyy hh24:mi:ss'), 'Site B' from dual union all
select 'Toto Tata', to_date ('28/08/2020 00:00:00','dd/mm/yyyy hh24:mi:ss'), 'Site B' from dual union all
select 'Toto Tata', to_date ('29/08/2020 00:00:00','dd/mm/yyyy hh24:mi:ss'), 'GRENOBLE' from dual union all
select 'Toto Tata', to_date ('30/08/2020 00:00:00','dd/mm/yyyy hh24:mi:ss'), 'GRENOBLE' from dual union all
select 'Toto Tata', to_date ('31/08/2020 00:00:00','dd/mm/yyyy hh24:mi:ss'), 'Site B' from dual union all
select 'Toto Tata', to_date ('01/09/2020 00:00:00','dd/mm/yyyy hh24:mi:ss'), 'Site B' from dual union all
select 'Toto Tata', to_date ('02/09/2020 00:00:00','dd/mm/yyyy hh24:mi:ss'), 'Site B' from dual union all
select 'Eric Toto', to_date ('03/09/2020 00:00:00','dd/mm/yyyy hh24:mi:ss'), 'GRENOBLE' from dual union all
select 'Maillot toto', to_date ('03/09/2020 00:00:00','dd/mm/yyyy hh24:mi:ss'), 'Site B' from dual union all
select 'Maillot toto', to_date ('04/09/2020 00:00:00','dd/mm/yyyy hh24:mi:ss'), 'Site B' from dual
)
, groupe_contact_site as (
select d.*
, row_number() over(partition by name order by daterdv)
- row_number() over(partition by name, nom order by daterdv) as grp
from data d
--order by name, daterdv
)
select name
, min(daterdv) as date_debut
, max(daterdv) as date_fin
, nom
from groupe_contact_site
group by name, nom, grp
order by name desc, date_debut; |
Partager