Search⌘ K
AI Features

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.

Query

SELECT type, AVG(age) AS avg_age
FROM pets
GROUP BY type
HAVING 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 ...