Erp100论坛's Archiver

xiangzhao 发表于 2008-7-12 14:42

如何删除存在多个重复记录中的一个

比如表内容为
no   jg
a    2
v    1
a    2
f    3
我想删除一个no=a,jg=2的记录。但是用delete from table where no=a,jg=2;的话会把两个都删除。我感觉要用pl/sql。请问有什么方法么?

xiangzhao 发表于 2008-7-12 14:42

DELETE FROM EMP E
WHERE E.ROWID > (SELECT MIN(X.ROWID)
                   FROM EMP X
                   WHERE X.EMP_NO = E.EMP_NO);

xiangzhao 发表于 2008-7-12 14:42

create table i(no varchar2(3),id number)
a 2
v 1
a 2
f 3
方法一
delete from i a where a.rowid<(select max(rowid) from i b where a.no=b.no)
方法二
delete from i where rowid in (select rowid from (select no,row_number()over(partition by no order by no) rn from i )
where rn>1)

xiangzhao 发表于 2008-7-12 14:42

delete from i a where a.rowid<(select max(rowid) from i b where a.no=b.no)

页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2007 Comsenz Inc.