Created
June 11, 2014 10:32
-
-
Save xtender/415103f3e724ae3a2847 to your computer and use it in GitHub Desktop.
start_of_group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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