Skip to content

Instantly share code, notes, and snippets.

@xtender
Created June 11, 2014 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtender/415103f3e724ae3a2847 to your computer and use it in GitHub Desktop.
Save xtender/415103f3e724ae3a2847 to your computer and use it in GitHub Desktop.
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