Grouping SQL results by continous time intervals (oracle sql)

Posted by Kamil Zadora on Stack Overflow See other posts from Stack Overflow or by Kamil Zadora
Published on 2009-01-09T09:00:57Z Indexed on 2010/04/09 17:33 UTC
Read the original article Hit count: 346

Filed under:
|
|
|
|

Hi I have following data in the table:

ID-----startDate----endDate
5549 2008-05-01 4712-12-31
5567 2008-04-17 2008-04-30 1
5567 2008-05-01 2008-07-31 1
5567 2008-09-01 4712-12-31 2

5569 2008-05-01 2008-08-31
5569 2008-09-01 4712-12-31
5589 2008-04-18 2008-04-30
5589 2008-05-01 4712-12-31
5667 2008-05-01 4712-12-31
5828 2008-06-03 4712-12-31
5867 2008-06-03 4712-12-31
6167 2008-11-01 4712-12-31
6207 2008-07-01 4712-12-31
6228 2008-07-01 4712-12-31
6267 2008-07-14 4712-12-31

I am looking for I way to group the continuous time intervals for each id to return:

ID, min(startDate), max(endDate),

to have something like this in result for the bolded ID 5567

5567 2008-04-17 2008-07-31
5567 2008-09-01 4712-12-31

PL/SQL is also an option here :)

Thanks,

© Stack Overflow or respective owner

Related posts about sql

Related posts about date