问题
I have a database table which looks as following:
id product_id product_name price date seller
1 646 Product 1 1 2020-05-20 Seller-A
2 1554 Product 2 1.50 2020-05-23 Seller-B
3 646 Product 1 2 2020-05-22 Seller-C
4 646 Product 1 2.5 2020-05-23 Seller-A
As a result I would like to get the latest info based on the date for every product_id.
2 1554 Product 2 1.50 2020-05-23 Seller-B
4 646 Product 1 2.5 2020-05-23 Seller-A
I have the following query which works fine for 1 product id:
SELECT * FROM (SELECT * FROM `table` WHERE 1 ORDER BY `date` DESC) t2 WHERE product_id = 646 GROUP BY `seller`
How should I build the query to get the results for multiple id's. At the moment it will only return the result for every seller available but no matter how many product ids are available
来源:https://stackoverflow.com/questions/62005692/query-for-latest-price-per-seller-per-product