初步认识下Oracel的ROW_NUMBER()Over(partition by order by )

-----删除重复数据

delete from cwgs.loan_buy_extendopr
 where oprno in (select oprno
          from (select d.oprno,
                       d.y_contno,
                       row_number() over(partition by y_contno order by y_contno) row_flag
                  from cwgs.loan_buy_extendopr d) t
         where t.row_flag > 1)


-----分组并组内排序,取第一条

select t.userno, t.corpno, t.departno
  from (select r.userno,
               r.corpno,
               r.departno,
               row_number() over(partition by r.departno order by r.userno asc) rn
          from fmsys.sys_userstation r
         where 1=1) t
 where t.rn = 1

你可能感兴趣的:(Oracle学习笔记)