在代碼中先用hashset裝載數(shù)據(jù),這樣就自動去重了因為set是不允許重復(fù)的,然后在批量插入到數(shù)據(jù)庫中就行了。
創(chuàng)新互聯(lián)建站成立與2013年,先為呼圖壁等服務(wù)建站,呼圖壁等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為呼圖壁企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
MYSQL里有五百萬數(shù)據(jù),但大多是重復(fù)的,真實的就180萬,于是想怎樣把這些重復(fù)的數(shù)據(jù)搞出來,在網(wǎng)上找了一圈,好多是用NOT IN這樣的代碼,這樣效率很低,自己琢磨組合了一下,找到一個高效的處理方式,用這個方式,五百萬數(shù)據(jù),十來分鐘就全部去除重復(fù)了,請各位參考。
第一步:從500萬數(shù)據(jù)表data_content_152里提取出不重復(fù)的字段SFZHM對應(yīng)的ID字段到TMP3表
1 create table tmp3 as select min(id) as col1 from data_content_152 group by SFZHM;
第二步:創(chuàng)建新表RES
1234 CREATE TABLE `res` (`id` int(11),`sfz` char(20)) ENGINE=MyISAM;
第三步:把TMP3表ID對應(yīng)到data_content_152里需要提取的數(shù)據(jù)添加到RES表的SFZ字段
1 INSERT INTO res (sfz) SELECT sfzhm FROM data_content_152,tmp3 where data_content_152.id=tmp3.col1
至此,就在MYSQL里實現(xiàn)了,給數(shù)據(jù)表data_content_152完全刪除重復(fù)數(shù)據(jù),把去重復(fù)后的數(shù)據(jù)導(dǎo)入到RES表。
利用group by
代碼如下:
SELECT * FROM(
select * from customer where user=(
SELECT source_user from customer WHERE user='admin') UNION ALL select * from customer where user=(
select source_user from customer where user=(
SELECT source_user from customer WHERE user='admin')) union ALL select * from customer where user=(
select source_user from customer where user=(
select source_user from customer where user=(
SELECT source_user from customer WHERE user='admin'))) UNION ALL select * from customer where source_user=(/*我的上線的上線的user*/
select user from customer where user=(
select source_user from customer where user=(
SELECT source_user from customer WHERE user='admin'))) union all select * from customer where source_user=(/*我的上線的上線的上線user*/
select user from customer where user=(
select source_user from customer where user=(
select source_user from customer where user=(
SELECT source_user from customer WHERE user='admin'))))) as alias group by user;
不建議直接刪除,養(yǎng)成良好的習慣(刪除更麻煩),以下是將去重后的數(shù)據(jù)轉(zhuǎn)移到另一張表代碼:
Insert into 表名(列名)select distinct 列名 from 表名
你可以按照去重的思路,刪除重復(fù)數(shù)據(jù)
delete from zhszty_ebook
where id not in(
select * from (select max(id) from zhszty_ebook group by url
) as tmp);------------mysql有個特性,對于表進行修改,刪除操作,子查詢不能和外層的查詢的表一樣,所以在加個select就可以了。其他數(shù)據(jù)庫按照樓上的那個是沒問題的
當前文章:mysql導(dǎo)入時怎么去重,mysql數(shù)據(jù)庫怎么去重
文章鏈接:http://www.ekvhdxd.cn/article8/phcoip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、網(wǎng)站排名、網(wǎng)站營銷、網(wǎng)站維護、關(guān)鍵詞優(yōu)化、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)