Oracle 數據分組,並找出每組中某字段最大值對應的那條數據


方法一:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM