cdharma
cdharma

Reputation: 1

Fetching the last value with a group by

I have table (T1) as below in oracle.

ReqTimestamp | ReqDuration | ServiceName | Marker

The query i am writing is :

select max(ReqDuration) from T1 group by ServiceName , Marker;

This give me max ReqDuration of every ServiceName,Marker in my table.

How can i get the value of the ReqDuration for the latest ReqTimestamp with the above result set.

Any pointers?

Upvotes: 0

Views: 36

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269445

Oracle provides the convenient keep/first syntax:

select max(ReqDuration),
       max(ReqDuration) keep (dense_rank first order by ReqTimeStamp desc)
from T1
group by ServiceName, Marker;

Upvotes: 2

Related Questions