sql删除重复数据

begin tran 
delete from WxUser_BMUser  
where   OpenId in (  select a.OpenId from WxUser_BMUser a where  IsUnBind=0
group by a.OpenId having COUNT(1)>1
) 
and   id not in (select min(id) from WxUser_BMUser  where IsUnBind=0  group by OpenId     having count(1)>1) 

rollback
commit
原文地址:https://www.cnblogs.com/yangjinwang/p/7279392.html