I have two tables, DATA (D DATE, P NUNBER — price, CUR_ID CHAR(3) — currency code), second table RATES (CUR_ID CHAR(3) — currency code, D DATE, R NUMBER — currency rate). I need calculate total price in one fixed currency. Next select stmt are correct, but query time is very long
SELECT SUM(D.P*R.R/R.N)
FROM DATA D, RATES R
WHERE R.CUD_ID=D.CUR_ID
AND R.DATE=(SELECT MAX(D) FROM RATES R2 WHERE R2.CUR_ID=D.CUR_ID AND R2.D<=D.D);
All indexes are present. How transform this query to decrease query time? Including pred date in RATES table and using range scan (R.PRED<=D.D AND D.D