I have a table with multiple entries. One entry consists of start Datetime and end datetime.
I want to find clusters of entries in such way that:
If an entry starts before the prior entry ends then both are part of the cluster. It is some kind of overlapping problem.
Example:
id start end
1 2007-04-11 15:34:02 2007-05-11 13:09:01
2 2007-06-13 15:42:39 2009-07-21 11:30:00
3 2007-11-26 14:30:02 2007-12-11 14:09:07
4 2008-02-14 08:52:11 2010-02-23 16:00:00
I want output of
id start end
1 2007-04-11 15:34:02 2007-05-11 13:09:01
2-4 2007-06-13 15:42:39 2010-02-23 16:00:00
I had a solution that sorts start and then does some calculations with rownumber and lag/lead and so on. The problem is the special case where line 4 does come directly after line 2 and so I don't recognize it...
Is there a good solution in sql here? Maybe I am missing something?