我正在尝试为列出的每种产品选择价格最低的产品列表。在上下文中,我有这些表:
**tb_product**
id | product | active | image | description
1 | shoes A | 1 | ... | ...
2 | shirt C | 1 | ... | ...
4 | pants E | 1 | ... | ...
---
**tb_store**
id | name | phone
11 | Store X | ...
22 | Store F | ...
33 | Store K | ...
---
**tb_product_store**
id_product | id_store | price
1 | 11 | 9.90
1 | 22 | 12.90
2 | 11 | 15.90
2 | 33 | 12.90
4 | 33 | 22.90
---
例如,我想选择价格最低的tb_product_store
表中列出的所有产品,结果如下:
id_product | product | price
1 | shoes A | 9.90
2 | shirt C | 12.90
4 | pants E | 22.90
我有这个问题:
SELECT
a.id, a.product,
MIN(b.price) as 'price'
FROM tb_product a
JOIN tb_product_store b ON b.id_product = a.id
WHERE a.active = 1
ORDER BY a.product
但是,此查询只返回一个价格最低的产品,而不是包含所有产品且价格最低的列表。
如何获得预期结果?
答案 0 :(得分:1)
case request @ _ -> _ / ValidStaticFile(file)