22,209
社区成员
发帖
与我相关
我的任务
分享
-- 假设总共有3个表:tab1,tab2,tab3
with t as
(select * from tab1 union all
select * from tab2 union all
select * from tab3
)
select *
from t a
inner join t b
on (a.起始IP between b.起始IP and b.终止IP
or a.终止IP between b.起始IP and b.终止IP
or b.起始IP between a.起始IP and a.终止IP
or b.终止IP between a.起始IP and a.终止IP)
and a.国家代码<>b.国家代码
--连接不是这样写的.
--试试:
select t1.startIpNum,t1.endIpNum,t2.startIpNum,t2.endIpNum,t1.country,t2.country
from a t1 inner join a t2 on t1.locid=t2.locid
where t1.startipnum>=t1.startipnum
and t1.endipnum<=t2.endipnum
and t1.country<>t2.country