新聞中心
java 批量插入mysql 怎么去重
在代碼中先用hashset裝載數(shù)據,這樣就自動去重了因為set是不允許重復的,然后在批量插入到數(shù)據庫中就行了。

創(chuàng)新互聯(lián)建站成立與2013年,先為呼圖壁等服務建站,呼圖壁等地企業(yè),進行企業(yè)商務咨詢服務。為呼圖壁企業(yè)網站制作PC+手機+微官網三網同步一站式服務解決您的所有建站問題。
怎么刪除重復的Mysql數(shù)據?
MYSQL里有五百萬數(shù)據,但大多是重復的,真實的就180萬,于是想怎樣把這些重復的數(shù)據搞出來,在網上找了一圈,好多是用NOT IN這樣的代碼,這樣效率很低,自己琢磨組合了一下,找到一個高效的處理方式,用這個方式,五百萬數(shù)據,十來分鐘就全部去除重復了,請各位參考。
第一步:從500萬數(shù)據表data_content_152里提取出不重復的字段SFZHM對應的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對應到data_content_152里需要提取的數(shù)據添加到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ù)據表data_content_152完全刪除重復數(shù)據,把去重復后的數(shù)據導入到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ù)據庫中怎么刪除重復的數(shù)據
不建議直接刪除,養(yǎng)成良好的習慣(刪除更麻煩),以下是將去重后的數(shù)據轉移到另一張表代碼:
Insert into 表名(列名)select distinct 列名 from 表名
你可以按照去重的思路,刪除重復數(shù)據
mysql數(shù)據庫怎么去除重復數(shù)據
delete from zhszty_ebook
where id not in(
select * from (select max(id) from zhszty_ebook group by url
) as tmp);------------mysql有個特性,對于表進行修改,刪除操作,子查詢不能和外層的查詢的表一樣,所以在加個select就可以了。其他數(shù)據庫按照樓上的那個是沒問題的
當前題目:mysql導入時怎么去重,mysql數(shù)據庫怎么去重
網站URL:http://fisionsoft.com.cn/article/phcoip.html


咨詢
建站咨詢
