invalid:聚合函数或GROUP BY子句

时间:2014-11-27 13:47:57

标签: mysql aggregate

嘿伙计们,我似乎无法弄清楚我在这里做错了什么。我对SQL很陌生,所以我无法解决这个问题。任何帮助都会很棒!

SELECT PC.Name AS [ProductCategoryName]   
,      MIN(PCH.StandardCost) AS MinStandardCost
,      AVG(PCH.StandardCost) AS AverageStandardCost
,      MAX(PCH.StandardCost) AS MaxStandardCost 
FROM    ProductCategory PC
INNER JOIN    Product P ON (PC.ProductCategoryID = P.ProductCategoryID)
INNER JOIN    ProductCostHistory PCH ON ( P.ProductID = PCH.ProductID)
WHERE PC.Name LIKE '%Bike%'

1 个答案:

答案 0 :(得分:0)

你忘记了group by子句:

SELECT PC.Name AS [ProductCategoryName]   
,      MIN(PCH.StandardCost) AS MinStandardCost
,      AVG(PCH.StandardCost) AS AverageStandardCost
,      MAX(PCH.StandardCost) AS MaxStandardCost 
FROM    ProductCategory PC
INNER JOIN    Product P ON (PC.ProductCategoryID = P.ProductCategoryID)
INNER JOIN    ProductCostHistory PCH ON ( P.ProductID = PCH.ProductID)
WHERE PC.Name LIKE '%Bike%'
group by PC.NAME