删除重复数据@mysql

来源:互联网 发布:合成歌曲的软件 编辑:程序博客网 时间:2024/06/10 07:38

mysql不能查找并更新同一张表

所以要建立一张临时表解决,

create table tmp asSELECT a.row FROM tg a where (a.phone,a.pack) in (select phone,pack from payoff_tg group by phone,pack having count(*) > 1) and row not in (select min(row) from tg group by phone,pack having count(*)>1);delete from tg where row in (select row from tmp); drop table tmp;


 上面太慢了换个方法

create table tmp asSELECT a.row FROM tg a where (a.phone,a.pack) in (select phone,pack from payoff_tg group by phone,pack having count(*) > 1) and row not in (select min(row) from tg group by phone,pack having count(*)>1);delete <span style="font-family: Arial, Helvetica, sans-serif;">tg </span><span style="font-family: Arial, Helvetica, sans-serif;"> from tg a,tmp b where a.row=b.row; </span>drop table tmp;


0 0
原创粉丝点击