17,377
社区成员
发帖
与我相关
我的任务
分享
-- 正确答案:
delete from tb t1
where exists ( select 1
from tb t2
where ((t2.a=t1.a and t2.b=t1.b) or (t2.a=t1.b and t2.b=t1.a))
and t2.id>t1.id );
-- 两端相同:加个or条件
delete from tb t1
where not exists ( select 1
from tb t2
where (t2.a=t1.a and t2.b=t1.b) or (t2.a=t1.b and t2.b=t1.a)
group by t2.a, t2.b
having min(id)=t1.id );
delete from tb t1
where not exists ( select 1
from tb t2
where t2.a=t1.a and t2.b=t1.b
group by t2.a, t2.b
having min(id)=t1.id );
select id,a,b
from tab
where id not in(
--选出重复的大的ID
select max(t.id)
from
(select id,a,b from tab
union all
select id,b as a,a as b from tab) t
group by t.a,t.b
having count(*)>1
)