我在 MySQL 上的表
table 供应商
---------------------------------------------------
SupplierID | SupplierName | ContactName Address
---------------------------------------------------
表格产品
-----------------------------------------------
ProductID | ProductName |SupplierID Unit| Price
-----------------------------------------------
查询
SELECT Suppliers.SupplierName
, ProductName
, Price
FROM Products
INNER JOIN (SELECT SupplierID
, MAX(Price) AS maxPrice
FROM Products
GROUP BY SupplierID) as gp ON Products.Price = gp.maxPrice
INNER JOIN Suppliers ON Suppliers.SupplierID = Products.SupplierID;
我想要做的是根据每个供应商最昂贵产品的价格获取产品名称、供应商名称及其各自的价格(这就是子查询正在提取的内容),但其余的查询不起作用,不知道为什么
SQL错误
Syntax error (missing operator) in query expression 'Products.Price =
gp.maxPrice INNER JOIN Suppliers ON Suppliers.SupplierID =
Products.SupplierID'.
最佳答案
SELECT Suppliers.SupplierName,ProductName,Price FROM (Products
INNER JOIN (SELECT SupplierID, MAX(Price) AS maxPrice FROM Products GROUP BY SupplierID) as gp ON Products.Price = gp.maxPrice)
INNER JOIN Suppliers ON Suppliers.SupplierID = Products.SupplierID;
有效果吗?
关于mysql - 内连接语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32019388/