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