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

CodePudding user response:

reference 1st floor xiaovhao response:
SELECT * FROM

(SELECT * FROM CHRDATAUPLOAD WHERE card_id=? The ORDER BY upload_time desc)

WHERE ROWNUM=1 sorted before the disaster area the first
this should be a faster way

CodePudding user response:

At present is not particularly large amount of data, try to use the method of the second floor, thank you

CodePudding user response:

The SELECT CARD_ID, UPLOAD_TIME
The FROM (SELECT tc ARD_ID,
T.U PLOAD_TIME,
MAX (UPLOAD_TIME) OVER (PARTITION BY CARD_ID) AS UPLOAD_TIME_
The FROM CHRDATAUPLOAD T) T
WHERE UPLOAD_TIME_=UPLOAD_TIME;

CodePudding user response:

reference
  

CodePudding user response:

Reference
 

CodePudding user response:

refer to the original poster had been based around the Java response:
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?


This writing has a problem, if all upload_time, estimation and the result is different as you might expect,
The most simple and crude way:
The select tc ard_id, MAX (t.u pload_time) upload_time from CHRDATAUPLOAD t GROUP BY tc ard_id;
  • Related