我需要使用最近的到期日期和销售价格来过滤数据,而不重复 id_product,我尝试解决这个问题,但我无法找到正确的方法来做到这一点
这是 Navicat 查询和结果
SELECT
product_exp_date.idproduct,
product_exp_date.exp_date,
product_exp_date.selling_price
FROM
product
INNER JOIN
product_exp_date
ON
product.idproduct = product_exp_date.idproduct
GROUP BY
product_exp_date.exp_date
idproduct exp_date selling_price 8 2022-11-01 300 5 2022-06-08 370 5 2022-06-09 350 7 2022-07-01 380 5 2022-09-20 450 6 2022-10-08 140 6 2023-06-08 150
我已经尝试过这种方式
GROUP BY
product_exp_date.idproduct
但它给了我不同的结果
idproduct exp_date selling_price 5 2022-06-09 350 6 2023-06-08 150 7 2022-07-01 380 8 2022-11-01 300
但我需要得到这个结果
idproduct exp_date selling_price 5 2022-06-08 370 6 2022-10-08 140 7 2022-07-01 380 8 2022-11-01 300
产品表
productid product_name 5 A 6 B 7 C 8 D
产品_EXP_日期表
idproduct_exp_date idproduct exp_date selling_price
1 5 2022-06-09 350
2 6 2023-06-08 150
3 5 2022-06-08 370
4 5 2022-09-20 450
5 6 2022-10-08 140
6 7 2022-07-01 380
7 8 2022-11-01 300
有时我的查询有一些错误,无论如何我需要帮助来解决这个问题, 谢谢。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号