方法一:
select serial_number,MAX_TIME,(select defect_id from g_sn_defect A where A.serial_number = B.serial_number and A.rec_time =B.MAX_TIME) defect_id from (select serial_number,max(rec_time) MAX_TIME from g_sn_defect where serial_number in (select serial_number from g_sn_status where rework_no='sj120206') group by serial_number) B
方法二:
select A.* from g_sn_defect A inner join ( select serial_number,max(rec_time) MAX_TIME from g_sn_defect where serial_number in (select serial_number from g_sn_status where rework_no='sj120206') group by serial_number ) B on B.serial_number = A.Serial_Number where B.MAX_TIME = A.rec_time