Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Slick way to compute intersection of intervals?

443806Sep 23 2009 — edited Sep 23 2009
Hello,

I was wondering if there is any slick way of computing this with only SQL. I have two pairs of numbers (could be dates too), and want to compute the intersection length. For example, if the numbers are (1, 5) and (2, 6), the answer is 3, that is 5 - 2. But if the numbers are (1,5) and (2,4), the answer is 2, i.e. 4 - 2 because (2,4) is wholly contained in (1,5).

Of course, I can use conditioning on all possible ordering combinations of the first and second interval's start and end points. But I was wondering if there is any slick way to do this that I have missed. Thanks,

Regards,

SK
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 21 2009
Added on Sep 23 2009
1 comment
442 views