------解决方案-------------------- select *
from tb a
where not exists (select 1 from tb b where a.phone1<>b.phone1 and a.phone2<>b.phone2 and
a.phone3<>b.phone3 and a.phone4<>b.phone4)
select phone1 as phone into #t from tb
union all select phone2 from tb
union all select phone3 from tb
union all select phone4 from tb
create clustered index pk_ix_#t_phone on #t(phone)
select phone1 as phone into #t1 from #insert
union all select phone2 from #insert
union all select phone3 from #insert
union all select phone4 from #insert
create clustered index pk_ix_#t1_phone on #t1(phone)
select a.phone into #p from #t a,#t1 b where a.phone=b.phone
create clustered index pk_ix_#p_phone on #p(phone)
--直接写not in效率应该很低,分开比较好,过滤掉大部分的话应该好一点
select * from #insert where phone1 not in (select phone from #p)
and phone2 not in (select phone from #p)
and phone3 not in (select phone from #p)
and phone4 not in (select phone from #p) ------解决方案--------------------
--先来一个全列表
WITH num
as
( SELECT iphone1 AS num
FROM TB
UNION
SELECT iphone2 AS num
FROM TB
UNION
SELECT iphone3 AS num
FROM TB