如何根据其他表参数选择与其他3个表连接的表格的多个最小记录?
我有一个问题。我有4个表:
- product_list
- product
- product_img
- pricelist
这个我的查询的样子:
SELECT
product_list.id,
product_list.class,
product.prod_name,
product.prod_url,
product.prod_overview,
product_img.list_prod340x340,
pricelist.price
FROM
(
(
(
product_list
INNER JOIN product ON product_list.id = product.prod_list_id
)
INNER JOIN product_img ON product.id = product_img.prod_id
)
INNER JOIN pricelist ON product.id = pricelist.prod_id
)
ORDER BY product_list.id, pricelist.price ASC
这是查询的结果 [查询结果] [1]: https://i.sstatic.net.net/v9jo1.jpg
所以问题就是这样。是,我如何仅获得每个prod_name的最低价格。
应将
方式 | ... | 返回 | | | 就是 | 的 |
---|---|---|---|---|---|---|
这 | 其 | | | | | |
| | | | | ... | 151600000 |
请帮忙吗?
I have a question. I have 4 tables:
- product_list
- product
- product_img
- pricelist
This what my query looks like:
SELECT
product_list.id,
product_list.class,
product.prod_name,
product.prod_url,
product.prod_overview,
product_img.list_prod340x340,
pricelist.price
FROM
(
(
(
product_list
INNER JOIN product ON product_list.id = product.prod_list_id
)
INNER JOIN product_img ON product.id = product_img.prod_id
)
INNER JOIN pricelist ON product.id = pricelist.prod_id
)
ORDER BY product_list.id, pricelist.price ASC
This is the result of the query
[QUERY RESULT]
[1]: https://i.sstatic.net/V9JO1.jpg
So the question is, how can i get only the lowest price of each prod_name.
This is how it should be returned
id | ... | prod_name | ... | ... | ... | price |
---|---|---|---|---|---|---|
1 | ... | Toyota Agya | ... | ... | ... | 155500000 |
2 | ... | Toyota Calya | ... | ... | ... | 151600000 |
please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请测试以下测试:
Please test this:
最简单的方法可能是以子查询获得价格:
由于MySQL 8.0.14,您可以从 rales将子查询移至
条款,并使此 hermant hermant Join ,这允许您从价格表中选择多个列:
The easiest approach is probably to get the price in a subquery:
Since MySQL 8.0.14 you can move the subquery to the
FROM
clause and make this a lateral join, which allows you to select more than one column from the price table: