I'm really stumped here ...
Let's say I have this “real numbers” table with columns BEGIN_NUM and END_NUM to represent a range of real numbers. The table will look something like this:
ID BEGIN_NUM END_NUM
-- --------- -------
A 1 10
B 11 20
C 21 30
D 55 70
We are assigned the starting number and ending number of the range. I need to develop an SQL query to see if this range of numbers is valid.
A simple case: given that 2 and 8, as our beginning and the end of our range, this will pass, since it falls into the Row A.
Hard cases: (# 1), data 5 and 15, this will go away, as it relates to Row A and Row B, which are essentially extensions of each other, making one large range that spans two lines. (1-10 and 11-20 = 1-20).
(# 2), 5 25, , (# 1), , . (1-10 11-20 21-30 = 1-30)
(â„– 3), 27 57, , , , Row C Row D , 31-54 ).
- , , . Oracle, .
:
select count(*)
from (select start_num, end_num
from ae_valid_vendor_nums
where '5' BETWEEN start_num AND end_num) tbl1,
(select start_num, end_num
from ae_valid_vendor_nums
where '25' BETWEEN start_num AND end_num) tbl2
where (tbl1.end_num - tbl2.start_num = -1)
OR (tbl1.start_num = tbl2.start_num AND tbl1.end_num = tbl2.end_num)
!