Solution: Ask Questions About Questions
Explore how to use SQL to ask advanced questions by grouping data and applying subqueries. Learn to calculate averages per category and filter these results by comparing them to overall averages. This lesson teaches you to summarize data effectively and gain insights through precise querying techniques.
We'll cover the following...
We'll cover the following...
Query
SELECT type, AVG(age) AS avg_ageFROM petsGROUP BY typeHAVING AVG(age) > (SELECT AVG(age)FROM pets);
Explanation
This query finds which types of pets have an average age greater than the overall average age of all pets.
Let’s break it down step by ...