當(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
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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Kingbase金仓查看表空间占用率
- 下一篇: u盘显示格式化怎么解决 U盘格式化问题,