Oracle 重复数据查询以及删除
視頻課:https://edu.csdn.net/course/play/7940
Create table test
(id number(2),
?names varchar2(20));
?insert into test values(2,'李四');
?insert into test values(3,'馬七');
?select * from test;
select * from test a where (a.id,a.names) in
?(select id,names from test group by id,names having count(*) > 1)
?delete from test a where (a.id,a.names) in
?(select id,names from test group by id,names having count(*) > 1)
? --查找重復(fù)數(shù)據(jù),不含rowid最小的行
? select * from test a where (a.id,a.names) in
? (select id,names from test group by id,names having count(*) > 1)
? and rowid not in (select min(rowid) from test group by id,names having count(*)>1)
?
---1.以上是重復(fù)數(shù)據(jù)根據(jù)多列來判斷
以下是重復(fù)數(shù)據(jù)根據(jù)單列來判斷
1、首先,查找表中多余的重復(fù)記錄,重復(fù)記錄是根據(jù)單個字段(id)來判斷
?
select * from test where id in(select id from test group by having count(id) >1)
?
2、刪除表中多余的重復(fù)記錄,重復(fù)記錄是根據(jù)單個字段(id)來判斷,只留有rowid最小的記錄
?
delete from test where (id) in (select id from test group by id having count(id) >1) and rowid not in (select min(rowid) from test group by id having count(*)>1)
總結(jié)
以上是生活随笔為你收集整理的Oracle 重复数据查询以及删除的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WEB入门之十九 UI
- 下一篇: WEB入门之二十 插件