新聞中心
MySQL數(shù)據(jù)庫中如何刪除部分關(guān)鍵字段重復(fù)的記錄呢?本文我們通過一個例子來介紹這一刪除方法,接下來我們先說一說這個例子。

創(chuàng)新互聯(lián)秉承實現(xiàn)全網(wǎng)價值營銷的理念,以專業(yè)定制企業(yè)官網(wǎng),成都做網(wǎng)站、成都網(wǎng)站設(shè)計,小程序開發(fā),網(wǎng)頁設(shè)計制作,手機網(wǎng)站制作,全網(wǎng)整合營銷推廣幫助傳統(tǒng)企業(yè)實現(xiàn)“互聯(lián)網(wǎng)+”轉(zhuǎn)型升級專業(yè)定制企業(yè)官網(wǎng),公司注重人才、技術(shù)和管理,匯聚了一批優(yōu)秀的互聯(lián)網(wǎng)技術(shù)人才,對客戶都以感恩的心態(tài)奉獻自己的專業(yè)和所長。
首先看一下Statistic表結(jié)構(gòu):
處理樣本:
主要實現(xiàn)目的:
刪除Date Server Item SubItem 完全相同,Id肯定不同,Value可能相同的記錄。
比如:
2011-07-27 | mx1.dns.com.cn | SEND_MAIL | TOTAL| 14522 | | 229 【刪除】
2011-07-27 | mx1.dns.com.cn | SEND_MAIL | TOTAL| 14795 | | 248 【保留】
實現(xiàn)過程:
***步:創(chuàng)建與Statistic表結(jié)構(gòu)完全相同的臨時表。
- use Statistic;
- create table s_tmp as select * from Statistic where 1=2;
第二步:根據(jù)Id(自動增長)提取較新數(shù)據(jù)到臨時表
- insert into s_tmp select a.* from Statistic a,Statistic b where
- a.Date=b.Date and a.Server=b.Server and a.Key=b.Key and a.SubKey=b.SubKey and a.id > b.id;
第三步:根據(jù)臨時表里的數(shù)據(jù)的日期信息,將原表的對應(yīng)日期的數(shù)據(jù)刪除
- delete from Statistic where Date in (select distinct Date from s_tmp );
第四步:將臨時表里的數(shù)據(jù)導(dǎo)入Statistic
- insert into Statistic select * from s_tmp;
第五步:***清空臨時表
- delete * from s_tmp;
實現(xiàn)結(jié)果:(去重后)
關(guān)于刪除MySQL表部分關(guān)鍵字段重復(fù)的方法就介紹到這里了,如果您想了解更多關(guān)于MySQL數(shù)據(jù)庫的知識,可以到這里看一下:http://database./mysql/,相信一定能夠帶給您收獲的。
文章題目:MySQL數(shù)據(jù)庫如何刪除表中部分關(guān)鍵字段重復(fù)的記錄
文章轉(zhuǎn)載:http://www.5511xx.com/article/djsigcj.html


咨詢
建站咨詢
