update RecyclingApplication set lastReturnDateTime = null where lastReturnDateTime is not null; update RecyclingApplication set lastReturnDateTime = (select lastRecyclingTime from (select ra.recyclingApplication_id, max(rr.recyclingTime) lastRecyclingTime from RecyclingApplication ra join invoicePlan ip on ip.id = ra.id join RecyclingRecord rr on rr.recyclingApplication_id = ra.id where ip.type = '申请还物单' group by ra.recyclingApplication_id) rs where rs.recyclingApplication_id = RecyclingApplication.id) where id in (select id from InvoicePlan ip where ip.type = '借物单');