خرید بک لینک

Vote count: 0

I have a table which stores the exchange rates of currencies on a given day (TBAADM.EXC). However the exchange rates are manually entered, and the erroneous rate entered previously has to be archived, so the table can end up having multiple entries of a given from-to exchange rate per day because of user error or because the exchange rate has changed during the day. To do this, I have a column in the table called UPDATE_NO which indicates that a given entry is the nth entry for the day. For example, the first exchange rate entry for the day will have an UPDATE_NO value of 001. If the exchange rate has changed or was entered incorrectly, the next entry will have a value of 002, and so on.

What I need to do now, is to get the latest entry of a from-to exchange rate for a given day:

select exc_rate
from tbaadm.exc
    where bank_id = 'BANK01'
    and designation = 'REV'
    and fr_ccy_code = 'USD'
    and to_ccy_code = 'PHP'
    and rtlist_date = '10-AUG-2015'
    and update_no = --maximum

This is what I currently have, but I think this would definitely affect the runtime of my script since I traverse the EXC table twice per record:

select exc_rate
    from tbaadm.exc
    where bank_id = 'BANK01'
    and designation = 'REV'
    and fr_ccy_code = 'USD'
    and to_ccy_code = 'PHP'
    and rtlist_date = '10-AUG-2015'
    and update_no = (select max(update_no) from tbaadm.exc
        where bank_id = 'BANK01'
        and designation = 'REV'
        and fr_ccy_code = 'USD'
        and to_ccy_code = 'PHP' 
        and rtlist_date = '10-AUG-2015')    

Is there a more efficient way to utilize the MAX() function? Any help will be appreciated.

asked 2 mins ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 28 بهمن 1394 ساعت: 11:34

صفحه بندی