目标
选择数据库中每个产品的最低/最高价格。
问题
我只能获得具有指定标识符的产品。
我有的
我正在使用MySQL,我有以下查询:
SELECT (MIN(`map`.`Product_Price`)) as `minProductPrice`,
(MAX(`map`.`Product_Price`)) as `maxProductPrice`,
`pr`.`Product_Name` as `productName`
FROM `bm_market_products` as `map`
JOIN `bm_products` as `pr`
JOIN `bm_markets` as `ma`
WHERE `map`.`Product_Id` = 1
AND `map`.`Product_Id` = `pr`.`Product_Id`
我的回报是minProductPrice
,maxProductPrice
和productName
。
解决方案
谢谢你的帮助。上面的两个答案都是正确的——但我选择了@GordonLinoff 的答案,因为我认为它对初学者更有用和更喜欢——但真的感谢你们俩。最终查询:
SELECT MIN(`map`.`Product_Price`) as `minProductPrice`,
MAX(`map`.`Product_Price`) as `maxProductPrice`,
`pr`.`Product_Name` as `productName`
FROM `bm_market_products` `map` join
`bm_products` as `pr`
on map`.`Product_Id` = `pr`.`Product_Id`
group by `map`.`Product_Id`
干杯!