Reputation: 315
In Microsoft Access, Northwind database, I have to show min and max of avg UnitPrice in different product categories using GROUP BY and HAVING. Here's what I tried:
SELECT MAX(SELECT AVG(UnitPrice) FROM Products) AS MaxSV, MIN(SELECT AVG(UnitPrice) FROM Products) AS
MinSV FROM Products GROUP BY CategoryID, UnitPrice HAVING DISTINCT CategoryID;
Second thing I have to do is show average of max UnitPrice by CategoryID, also using GROUP BY and HAVING.
Upvotes: 4
Views: 885
Reputation: 1878
Try this:
SELECT MAX(t1.avg_price), MIN(t1.avg_price)
FROM (SELECT AVG(UnitPrice) AS avg_price
FROM Products
GROUP BY CategoryID) AS t1
Upvotes: 3