select *
from a,b
where a.id between b.start_ip and b.end_ip

解决方案 »

  1.   

    再请问:
    如果存在重复包含的情况(一个ip同时满足几个ip段),那么我只想保留其中的一个结果,怎么办呢?
    比如说,一个ip同时包含在两个ip段中,那么查询结果会产生两条记录,但我只想保留一条记录(比如最上面的一条),请问该怎么办呢?
      

  2.   

    select * from 
    (select * from a,b
    where a.id between b.start_ip and b.end_ip) t1
    where not exists(select 1 from b where t1.id between start_ip and end_ip and start_ip < t1.start_ip )