表
create table AA_TEST
( aaaa NVARCHAR2(20), bbbb NUMBER, cccc NVARCHAR2(20) )删除分两步:先保存满足要求的
delete from aa_test t where (t.aaaa,t.bbbb) not in (
select t1.aaaa,max(t1.bbbb) from aa_test t1 group by t1.aaaa);
第二步再在第一步基础上删去重复记录
delete from aa_test t where rowid not in( select min(rowid) from aa_test t1 where t.aaaa = t1.aaaa and t.bbbb = t1.bbbb);
第二种方式 ,使用开窗函数
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 )备注:
row_number()要配合over(order by xxx)进行使用,row_number()从1开始,为每一条分组记录返回一个数字