I have a table T1, it contains a NAME value (not unique), and a date range (D1 and D2 which are dates) When NAME are the same, we make a union of the date ranges (e.g. B).
But as a result (X), we need to make intersection of all the date ranges
Edit: Table T1
NAME | D1 | D2
A | 20100101 | 20101211
B | 20100120 | 20100415
B | 20100510 | 20101230
C | 20100313 | 20100610
Result :
X | 20100313 | 20100415
X | 20100510 | 20100610
Visually, this will give the following :
NAME : date range
A : [-----------------------]-----
B : --[----]----------------------
B : ----------[---------------]---
C : -----[--------]---------------
Result :
X : -----[-]----------------------
X : ----------[---]---------------
Any idea how to get that using SQL / PL SQL ?