Answer the question
In order to leave comments, you need to log in
How to display the current price of the goods if they change every day?
Hi friends!
There is a product table sku: id, sku, name
and there is a price table sku_costs: id, sum, datefrom
Where datefrom is the date the price was changed and sum is the new price:
2,500,2018-02-01 10:00:00
2,550,2018-02-05 18:00:00
select s.*, sc.`sum`, max(sc.datefrom) from sku s
left join sku_costs sc
on s.id = sc.id
group by s.id
Answer the question
In order to leave comments, you need to log in
SELECT
s.`id`,
(select sc.`sum` FROM `sku_costs` sc WHERE sc.`id`=s.`id` ORDER BY sc.`datefrom` DESC LIMIT 1) AS `price`
FROM `sku` s
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question