新聞中心
java 批量插入mysql 怎么去重
在代碼中先用hashset裝載數(shù)據(jù),這樣就自動(dòng)去重了因?yàn)閟et是不允許重復(fù)的,然后在批量插入到數(shù)據(jù)庫(kù)中就行了。
創(chuàng)新互聯(lián)建站成立與2013年,先為呼圖壁等服務(wù)建站,呼圖壁等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為呼圖壁企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
怎么刪除重復(fù)的Mysql數(shù)據(jù)?
MYSQL里有五百萬(wàn)數(shù)據(jù),但大多是重復(fù)的,真實(shí)的就180萬(wàn),于是想怎樣把這些重復(fù)的數(shù)據(jù)搞出來(lái),在網(wǎng)上找了一圈,好多是用NOT IN這樣的代碼,這樣效率很低,自己琢磨組合了一下,找到一個(gè)高效的處理方式,用這個(gè)方式,五百萬(wàn)數(shù)據(jù),十來(lái)分鐘就全部去除重復(fù)了,請(qǐng)各位參考。
第一步:從500萬(wàn)數(shù)據(jù)表data_content_152里提取出不重復(fù)的字段SFZHM對(duì)應(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對(duì)應(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里實(shí)現(xiàn)了,給數(shù)據(jù)表data_content_152完全刪除重復(fù)數(shù)據(jù),把去重復(fù)后的數(shù)據(jù)導(dǎo)入到RES表。
MySQL中怎么去重
利用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;
mysql數(shù)據(jù)庫(kù)中怎么刪除重復(fù)的數(shù)據(jù)
不建議直接刪除,養(yǎng)成良好的習(xí)慣(刪除更麻煩),以下是將去重后的數(shù)據(jù)轉(zhuǎn)移到另一張表代碼:
Insert into 表名(列名)select distinct 列名 from 表名
你可以按照去重的思路,刪除重復(fù)數(shù)據(jù)
mysql數(shù)據(jù)庫(kù)怎么去除重復(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有個(gè)特性,對(duì)于表進(jìn)行修改,刪除操作,子查詢不能和外層的查詢的表一樣,所以在加個(gè)select就可以了。其他數(shù)據(jù)庫(kù)按照樓上的那個(gè)是沒(méi)問(wèn)題的
新聞標(biāo)題:mysql導(dǎo)入時(shí)怎么去重,mysql數(shù)據(jù)庫(kù)怎么去重
網(wǎng)頁(yè)鏈接:http://fisionsoft.com.cn/article/phcoip.html