刪除重複數據@mysql

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;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章