Solution: Only Keep Interesting Groups
Understand how to refine grouped SQL query results by applying the HAVING clause to filter aggregates. Learn to calculate averages per group and display only groups meeting specific conditions, such as cities with an average age below 28.
We'll cover the following...
We'll cover the following...
Query
SELECT city, AVG(age) AS avg_ageFROM peopleGROUP BY cityHAVING AVG(age) < 28;
Explanation
This query finds the average age of people in each city, but only shows cities where the average age is less than 28. ...