Answer the question
In order to leave comments, you need to log in
Is it possible to make such a report in pure SQL?
There is such a task:
We solved it like this in MySQL:
SELECT item_id, price * IFNULL(rate, 1) as price_in_byr
FROM items
LEFT JOIN (SELECT * FROM (SELECT * FROM `rates` ORDER BY date DESC) r group by currency) rmax
ON items.currency = rmax.currency
Answer the question
In order to leave comments, you need to log in
SELECT i.item_id as item_id, (i.price * r.rate) as price_in_byr
FROM items i, rates r
WHERE r.date = max(r.date) AND i.curency = r.curency
ну и если интересует конкретный итем AND i.item_id = 1
Syntax highlighting is gone.
Something like this:
select
t1.item_id,
t1.price,
t1.currency,
t2.rate
from items t1
left join (
select
t3.rate,
t4.currency,
t4.date
from rates t3
inner join (
select
currency,
max( date)
from rates
group by currency) t4
on t4.currency = t3.currency
and t4.date = t3.date) t2
on t1.currency = t2.currency
where t1.item_id = 5
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question