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

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


咨詢
建站咨詢
