亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

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

瀏覽:63日期:2023-10-11 15:22:54

有一個(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)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: MySQL 數(shù)據(jù)庫(kù)
相關(guān)文章:
主站蜘蛛池模板: 亚洲欧美日本国产综合在线 | 来个黄色网址 | 草草免费 | 特级深夜a级毛片免费观看 特极毛片 | 1024cao社区榴地址一地址二 | 激情亚洲综合网 | 一级做a爰性色毛片免费 | 美女在线国产 | 精品国产999 | 成人精品视频一区二区三区尤物 | 国产精品美女一区二区三区 | 在线视频一二三区2021不卡 | 亚洲色图在线观看 | 青青草91在线 | 久草久在线 | 青青热久免费精品视频精品 | 全免费a级毛片免费看视频免 | 视频在线观看免费播放www | 你懂得在线网址 | 91国在线高清视频 | 国产成人午夜精品影院游乐网 | 日韩性视频网站 | 欧美色黄 | 欧美桃色视频 | 麻豆网站在线看 | 欧美成人香蕉网在线观看 | 精品国产网 | 亚洲天堂三区 | 欧美成人影院 在线播放 | 永久在线观看www免费视频 | 日本欧美不卡一区二区三区在线 | 一级香蕉视频在线观看 | 亚洲欧美另类国产 | 欧美日韩亚洲国内综合网香蕉 | 国产一区二区在线视频 | 国内欧美一区二区三区 | 亚州αv| 国产精品短视频免费观看 | 国产伦理自拍 | 免费特黄| 999人在线精品播放视频 |