当前位置:
首页 >
SQL表内查重和删重
发布时间:2025/5/22
33
豆豆
生活随笔
收集整理的这篇文章主要介绍了
SQL表内查重和删重
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
###查询重复记录
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;###查询重复记录(多个条件)
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;###删除重复记录(只留一条)
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);总结
以上是生活随笔为你收集整理的SQL表内查重和删重的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Kingbase金仓查看表空间占用率
- 下一篇: PostgreSQL连接情况查询