使用Oracle分析函式去除重複記錄

woodnan發表於2008-04-11

1、建立個實驗表

create table t (a number);
insert into t values(1);
insert into t values(1);
insert into t values(1);
insert into t values(2);
insert into t values(2);
insert into t values(3);

commit;

2、可以使用下列SQL去除重複記錄

delete t where rowid in
(
select rowid,a,b from
(
select a,lead(a,1) over (partition by a order by a) as b from t
)
where a=b
);

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/175187/viewspace-1002345/,如需轉載,請註明出處,否則將追究法律責任。

相關文章