溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

mysql刪除重復數(shù)據(jù)

發(fā)布時間:2020-08-10 14:49:18 來源:ITPUB博客 閱讀:153 作者:guyuanli 欄目:MySQL數(shù)據(jù)庫
mysql刪除重復數(shù)據(jù)分為兩種情況:
一、以一個字段來唯一確定一條記錄,可以用以下SQL來刪除:
delete glt_entity_tmp from glt_entity_tmp,(select idd from glt_entity_tmp group by nam having count(*) > 1 ) as t2
where glt_entity_tmp.idd=t2.idd

注意:數(shù)據(jù)中idd不一致,其它字段信息都一致,如果是一個nam有多于2條重復的記錄,要執(zhí)行多次

二、以二個或以上字段來唯一確定一條記錄,可以用以下SQL來刪除,但要注意每條記錄中必須有第三個字段來唯一確定這條記錄(使用max刪除)
delete gbi_pd_theme_new_tmp from gbi_pd_theme_new_tmp,(select new_code,the_code,max(the_new_code) as the_new_code from gbi_pd_theme_new_tmp group by new_code,the_code having count(*) > 1) as t2
where gbi_pd_theme_new_tmp.new_code=t2.new_code and gbi_pd_theme_new_tmp.the_code=t2.the_code and gbi_pd_theme_new_tmp.the_new_code=t2.the_new_code

注意:如果是有多于2條重復的記錄,要執(zhí)行多次
因為此例子中每條記錄有一個唯一的字段the_new_code,所以可以用max來刪除重復記錄

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI