日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

SQL表内查重和删重

發(fā)布時(shí)間:2025/5/22 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SQL表内查重和删重 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

###查詢重復(fù)記錄

select * from my_tab where dup_col in(select dup_col from my_tabgroup by dup_col having count(dup_col)>1)order by dup_col;

###查詢重復(fù)記錄(多個(gè)條件)

select * from my_tab as t1 where ( select count(*) from my_tab t2 where t2.col_1=t1.col_1 and t2.col_2=t1.col_2 and t2.col_3=t1.col_3 and t2.col_4=t1.col_4 )>1;

###刪除重復(fù)記錄(只留一條)
PG:使用ctid

delete from my_tab where dup_col in (select dup_col from my_tab group by dup_col having count(dup_col) > 1) and ctid not in (select min(ctid) from my_tab group by dup_col having count(dup_col)>1); delete from table_1 where (col_1,col_2,col_3) in (select col_1,col_2,col_3 from table_1 group by col_1,col_2,col_3 having count(*) > 1) and ctid not in (select min(ctid) from table_1 group by col_1,col_2,col_3 having count(*)>1);

ORACLE:使用rowid

delete from my_tab where dup_col in (select dup_col from my_tab group by dup_col having count(dup_col) > 1) and rowid not in (select min(rowid) from my_tab group by dup_col having count(dup_col)>1);

總結(jié)

以上是生活随笔為你收集整理的SQL表内查重和删重的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。