我有一个包含表的数据库:
suppliers:
fid , name
1 | 'Andrey'
2 | 'lucas'
products:
pid , name
1 | 'X'
2 | 'Y'
prdtFrn:
pid , fid , price
---------------- supplier 'andrey'
1 | 1 | 19.00
2 | 1 | 16.00
----------------- supplier 'lucas'
1 | 2 | 14.00
2 | 2 | 18.00
查询产品,我得到了所有已注册的产品,但我需要知道谁以最低价格销售“产品表”的当前产品,我不知道如何编写查询
最佳答案
select p.*
from (
select pid, min(price) as MinPrice
from prdtFrn
group by pid
) pm
inner join prdtFrn p on pm.pid = p.pid and pm.MinPrice = p.price
您会看到每个产品有多行,其中两个供应商以相同的价格销售产品。
关于mysql - 谁卖的价格最低,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9263672/