External Exam Download Resources Web Applications Games Recycle Bin

Group By, Having

groupby1.sql

SELECT COUNT(*) AS 'number of items available', category
FROM menu
GROUP BY category

groupby2.sql

SELECT category, ROUND(AVG(price),2) AS 'average price'
FROM menu
GROUP BY category

groupby3.sql

SELECT category, ROUND(AVG(price),2) AS 'average price'
FROM menu
GROUP BY category
HAVING AVG(price) > 15.00
  1. Explain how GROUP BY works.
  2. show the MAX price for each category group
  3. if you are struggling with the previous query:
    SELECT MAX(price), category
    FROM menu
    GROUP BY ...
  4. For the query you just wrote, show only the category groups HAVING MAX(price) > 20.0
  5. do another GROUP BY category query, this time using MIN. What does this tell us?