oracle 根据分组取日期最大的那条数据


SELECT
    po_line_id,
    consigned_flag,
    need_by_date 
FROM
    (
    SELECT
        t.rn,
        t.consigned_flag,
        t.need_by_date,
        t.po_line_id 
    FROM
        (
        SELECT
            ROW_NUMBER ( ) OVER ( PARTITION BY plla.po_line_id ORDER BY plla.need_by_date DESC ) rn,
            plla.po_line_id,
            plla.consigned_flag,
            plla.need_by_date 
        FROM
            po_line_locations_all plla 
        ) t 
    WHERE
        t.rn = 1 
    ) m 
WHERE
    m.po_line_id = 44150;

 

注:PARTITION BY 为分组字段

       ORDER BY 根据日期排序  

       desc 倒序,ROW_NUMBER() OVER(PARTITION BY plla.po_line_id ORDER BY plla.need_by_date DESC) rn 为序号

      rn=1取倒序排序的第一条

  

 


免责声明!

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



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