Home > database > Oracle the same ID with multiple records, how to take the one time the largest
Oracle the same ID with multiple records, how to take the one time the largest
Time:09-17
The select tc ard_id, t.u pload_time from CHRDATAUPLOAD t where T.u pload_time=(select Max (t1. Upload_time) from CHRDATAUPLOAD t1 where t1. Card_id=tc ard_id)
Said card_id note: here is the title of id, in addition to the Max (), what is more convenient, more faster way?
CodePudding user response:
SELECT * FROM
(SELECT * FROM CHRDATAUPLOAD WHERE card_id=? The ORDER BY upload_time desc)
WHERE ROWNUM=1 sorted before the first
CodePudding user response:
- habit to write so, don't know whether I better, scan only one table,
select Arthur c. ard_id, c.u pload_time The from (select t. *, - the descending Max first Row_number () over (partition by tc ard_id order by t.u pload_time desc) rn The from CHRDATAUPLOAD t) c Where an rn=1;
CodePudding user response:
The select tc ard_id, t.u pload_time from CHRDATAUPLOAD t where (tc ard_id, t.u pload_time) in (select t1 card_id, Max (t1) upload_time) from CHRDATAUPLOAD t1 group by t1. The card