oracle 当查询结果有重复记录时 选择时间最近的一条

select
  dd.receive_person,
       dd.borrow_date,
       dd.return_date,
       dd.check_status,
       da.reason,
       dd.pk,
       rb.resource_name,
       rb.resource_brand,
       da.pk dapk,
        ws.bar_code
  from rm_device_detail dd
  left join rm_warehousing_stock ws
    on dd.warehousing_stock_pk = ws.pk
  left join rm_device_apply da
    on dd.device_apply_pk = da.pk
  left join rm_warehousing_documents wd
    on wd.pk = ws.warehousing_documents_pk
  left join rm_base rb
    on wd.base_pk = rb.pk
 where dd.borrow_status = '8'
   and dd.check_status != 'A'
   and dd.return_date is not null
   and not exists(select 1 from rm_device_detail sub where dd.warehousing_stock_pk=sub.warehousing_stock_pk 
   and )
order by dd.return_date desc

你可能感兴趣的:(oracle 当查询结果有重复记录时 选择时间最近的一条)