mysql不能查找并更新同一张表
所以要建立一张临时表解决,
create table tmp as
SELECT 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 as
SELECT 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;