有这样的一张表:
msgid content
2003 a
2003 a
2003 f
2004 b
2004 c
2005 d
2006 e
在这张表中,列2003、2004重复了,现在把列重复的记录删掉,只保留一条(任意一条),如:
msgid content
2003 a
2004 b
2005 d
2006 e
create table qxjtest(msgid varchar2(20),content varchar2(20));
insert into qxjtest values('2003','a');
insert into qxjtest values('2003','a');
insert into qxjtest values('2003','f');
insert into qxjtest values('2004','b');
insert into qxjtest values('2004','c');
insert into qxjtest values('2005','d');
insert into qxjtest values('2006','e');
commit ;
delete qxjtest
where rowid in
(
select rowid from (
select msgid,
content,
lag(msgid,1) over (order by msgid) as msgid1
from qxjtest order by msgid
) a
where a.msgid=a.msgid1
)
===================
delete from table_name
where rowid in
(select t.rid
from (select rowid rid,row_number() over (partition by msgid order by msgid) rnb
from table_name) t
where t.rnb > 1);