Predict Subquery Result
Predict Output Medium
Question
Order totals are: 10, 20, 30, 40. How many rows have total > AVG(total)?
Code
SELECT COUNT(*) FROM orders WHERE total > (SELECT AVG(total) FROM orders);
Hint
First compute the average, then count rows above it.
Explanation
AVG(total) = (10+20+30+40)/4 = 25. Rows with total > 25 are 30 and 40 — that is 2 rows.
Related Resources
Related Lessons
- Subqueries
Learn subqueries.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.