Predict HAVING Filter
Predict Output Medium
Question
Groups have counts: user1=3, user2=1, user3=5. How many pass HAVING COUNT(*) > 2?
Code
SELECT user_id FROM orders GROUP BY user_id HAVING COUNT(*) > 2;
Hint
HAVING filters groups after counting.
Explanation
HAVING COUNT(*) > 2 keeps groups with more than 2 orders. User1 (3) and user3 (5) pass; user2 (1) does not. Result: 2 rows.
Related Resources
Related Lessons
- GROUP BY
Learn HAVING.
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.