Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MAX function

Status
Not open for further replies.

toray

IS-IT--Management
Nov 6, 2002
5
0
0
GB
I am trying to extract the latest date for a currency rate located in a oracle database table.
The data in the table includes many entries for each currency code. For example the Euro has 12 entries ie 12 dates,and I need the last date entry to get the current rate.
The MAX function works find until I add the numeric rate.ie I get all the currency rates.
How do i associate the currency rate to the MAX date?
 
You probably need to look at WINDOWING functions e.g. RANK, ROW_NUMBER. These enable you not just to get the highest value but the other columns on that row.

The query would look something like:

Code:
select currency, rate, rate_date
from
(select currency,
        rate, 
        rate_date,
        rank() over (partition by currency order by rate_date desc) as rn
from currencies)
where rn=1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top