Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
start_of_group
select
chairperson
,grp as period
,min(date_from) keep (dense_rank first order by date_from,date_to) as date_from
,max(date_to ) keep (dense_rank last order by date_from,date_to) as date_to
from (
select
chairperson
, date_from
, date_to
, sum(flag) over(partition by chairperson order by date_from,date_to) grp
from (
select
chairperson
, date_from
, date_to
, decode( 1 + lag(date_to)over(partition by chairperson order by date_from,date_to), date_from, 0, 1) flag
from chairmanships
)
)
group by chairperson, grp
order by chairperson, grp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.