久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

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

瀏覽:6日期: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)語句的詳細(xì)內(nèi)容,更多關(guān)于MySQL 數(shù)據(jù)查重、去重的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: MySQL 數(shù)據(jù)庫
相關(guān)文章:
主站蜘蛛池模板: 五华县| 诸暨市| 驻马店市| 商城县| 崇左市| 新乡县| 高雄县| 城市| 和硕县| 辽阳县| 缙云县| 德格县| 黄梅县| 遂川县| 余庆县| 铁力市| 邢台县| 乃东县| 安龙县| 彝良县| 随州市| 宁津县| 铁岭县| 琼海市| 和田市| 遂宁市| 吉林市| 黄梅县| 雅江县| 新泰市| 岳普湖县| 天台县| 邯郸县| 定结县| 云浮市| 厦门市| 襄城县| 瑞丽市| 西华县| 咸阳市| 宝兴县|