Hey guys I can't seem to figure out what I'm doing wrong here. I'm quite new to SQL so I can't wrap my head around this. Any help would be great!
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%'
You forgot the group by clause:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.