SELECT item_id,
CASE
WHEN I.currency IN ('EUR','USD')
THEN I.price * R.rate
ELSE I.price * 1
END AS price_in_byr
FROM Items AS I LEFT JOIN Rates AS R ON I.currency = R.currency
AND R.date = (SELECT MAX(date)
FROM Rates
WHERE I.currency = R.currency
)
WHERE item_id = 6
;
SELECT item_id,
CASE I.currency
WHEN 'BYR'
THEN I.price * 1
ELSE I.price * R.rate
END price_in_byr
FROM Items AS I FULL JOIN Rates AS R ON I.currency = R.currency
AND R.date = (SELECT MAX(date) FROM Rates WHERE Rates.currency = I.currency)
WHERE item_id = 2
;