I have a table(begin, end, typeid) with time intervals, something like this:
...
14:10:44 14:15:51 1
14:12:33 14:18:42 2
15:24:09 15:24:17 1
...
There is some rules: intervals with type id 2 intersepts with intervals of type 1.
And after processing I get something like this:
...
14:10:44 14:18:42 <-- as a result of merging
15:24:09 15:24:17
...
Is there exists any tehnics or methods to work with such data? May be there exists any usefull representation of intervals of time?
P.S. SQL Server 2008 R2
It is really hard to code up against data like yours. I have seen it a couple of times in real life situations. Here are 2 ideas.
Here is an alternative way. May even be better, depending on your data.
I am assuming that the low with type_id 1 is always the lowest in the set. I am also assuming there are no overlapping sets for rows with type_id 1 (and their subrows) since that would make no sense at all.