表 函數
create table AA_TEST
(
aaaa NVARCHAR2(20),
bbbb NUMBER,
cccc NVARCHAR2(20)
) it
刪除分兩步:先保存知足要求的 io
delete from aa_test t where (t.aaaa,t.bbbb) not in ( table
select t1.aaaa,max(t1.bbbb) from aa_test t1 group by t1.aaaa); test
第二步再在第一步基礎上刪去重複記錄 基礎
delete from aa_test t where rowid not in(); select
第二種方式 ,使用開窗函數 tab
delete from AA_TEST where rowid in
(
select rowid from
(
select t.aaaa,t.bbbb,rowid, row_number() over(partition by t.aaaa order by t.bbbb desc) as cccc from AA_TEST t
)c
where c.cccc > 1
) di
備註: let
row_number()要配合over(order by xxx)進行使用,row_number()從1開始,爲每一條分組記錄返回一個數字