主頁(yè) > 知識(shí)庫(kù) > MySQL 數(shù)據(jù)查重、去重的實(shí)現(xiàn)語(yǔ)句

MySQL 數(shù)據(jù)查重、去重的實(shí)現(xiàn)語(yǔ)句

熱門(mén)標(biāo)簽:許昌外呼增值業(yè)務(wù)線路 廣東400企業(yè)電話(huà)申請(qǐng)流程 咸陽(yáng)防封電銷(xiāo)卡 臨沂做地圖標(biāo)注 申請(qǐng)400電話(huà)電話(huà)價(jià)格 宜賓全自動(dòng)外呼系統(tǒng)廠家 新鄉(xiāng)智能外呼系統(tǒng)好處 石家莊400電話(huà)辦理公司 地圖標(biāo)注客戶(hù)付款

有一個(gè)表user,字段分別有id、nick_name、password、email、phone。

一、單字段(nick_name)

查出所有有重復(fù)記錄的所有記錄

select * from user where nick_name in (select nick_name from user group by nick_name having count(nick_name)>1);

查出有重復(fù)記錄的各個(gè)記錄組中id最大的記錄

select * from user where id in (select max(id) from user group by nick_name having count(nick_name)>1);

查出多余的記錄,不查出id最小的記錄

select * from user where nick_name in (select nick_name from user group by nick_name having count(nick_name)>1) and id not in (select min(id) from user group by nick_name having count(nick_name)>1);

刪除多余的重復(fù)記錄,只保留id最小的記錄

delete from user where nick_name in (select nick_name from (select nick_name from user group by nick_name having count(nick_name)>1) as tmp1) and id not in (select id from (select min(id) from user group by nick_name having count(nick_name)>1) as tmp2);

二、多字段(nick_name,password)

查出所有有重復(fù)記錄的記錄

select * from user where (nick_name,password) in (select nick_name,password from user group by nick_name,password where having count(nick_name)>1);
 

查出有重復(fù)記錄的各個(gè)記錄組中id最大的記錄

select * from user where id in (select max(id) from user group by nick_name,password where having count(nick_name)>1);

查出各個(gè)重復(fù)記錄組中多余的記錄數(shù)據(jù),不查出id最小的一條

select * from user where (nick_name,password) in (select nick_name,password from user group by nick_name,password having count(nick_name)>1) and id not in (select min(id) from user group by nick_name,password having count(nick_name)>1);

刪除多余的重復(fù)記錄,只保留id最小的記錄

delete from user where (nick_name,password) in (select nick_name,password from (select nick_name,password from user group by nick_name,password having count(nick_name)>1) as tmp1) and id not in (select id from (select min(id) id from user group by nick_name,password having count(nick_name)>1) as tmp2);

以上就是MySQL 數(shù)據(jù)查重、去重的實(shí)現(xiàn)語(yǔ)句的詳細(xì)內(nèi)容,更多關(guān)于MySQL 數(shù)據(jù)查重、去重的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

您可能感興趣的文章:
  • MySQL使用show status查看MySQL服務(wù)器狀態(tài)信息
  • Mysql中 show table status 獲取表信息的方法
  • mysql建表常用的sql語(yǔ)句匯總
  • 記一次MySQL更新語(yǔ)句update的踩坑
  • Navicat Premium操作MySQL數(shù)據(jù)庫(kù)(執(zhí)行sql語(yǔ)句)
  • MySQL兩種刪除用戶(hù)語(yǔ)句的區(qū)別(delete user和drop user)
  • MySQL 數(shù)據(jù)庫(kù) like 語(yǔ)句通配符模糊查詢(xún)小結(jié)
  • mysql中寫(xiě)判斷語(yǔ)句的方法總結(jié)
  • MySQL 常用的拼接語(yǔ)句匯總
  • MySQL SHOW STATUS語(yǔ)句的使用

標(biāo)簽:阜新 合肥 鷹潭 鎮(zhèn)江 貴州 臺(tái)灣 日照 北京

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《MySQL 數(shù)據(jù)查重、去重的實(shí)現(xiàn)語(yǔ)句》,本文關(guān)鍵詞  MySQL,數(shù),據(jù)查,重,去,重的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《MySQL 數(shù)據(jù)查重、去重的實(shí)現(xiàn)語(yǔ)句》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于MySQL 數(shù)據(jù)查重、去重的實(shí)現(xiàn)語(yǔ)句的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章