oracle开窗函数:先分组,再按时间排序取第一条


select  t.*  
   from (select a.*, row_number() over(partition by 需要分组的字段 order by 更新时间 desc) rw  
           from 表 a) t  
  where t.rw = 1  

实例:

select  t.*  
   from (select a.orgid,a.createdate, row_number() over(partition by orgid order by createdate desc) rw  
           from sec_per_complainlist a where a.yearmonth = '2018-01'
           and a.status in ('4', '5', '6', '7') /**状态为最终**/) t  
  where t.rw = 1  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM