我有一个记录集如下:
company_id po_date po_number supplier_company_id
1 01/01/2017 1000 20
1 02/01/2017 1001 20
1 03/01/2017 1002 20
2 01/02/2017 1005 30
2 02/02/2017 1006 30
2 03/02/2017 1007 30
我希望返回每个company_id的最新日期的记录
company_id po_date po_number supplier_company_id
1 03/01/2017 1002 20
2 03/02/2017 1007 30
答案 0 :(得分:0)
使用此
select * from
(select t.*,row_number() over (partition by company_id order by po_date desc) rn
from your_table t)
where rn=1