0
0
SQLquery~20 mins

WHERE vs HAVING mental model in SQL - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WHERE vs HAVING Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding WHERE clause filtering
Which statement best describes when the WHERE clause is applied in an SQL query?
AIt filters rows before any grouping or aggregation happens.
BIt filters groups after aggregation is done.
CIt filters columns after the SELECT statement.
DIt filters the final result set after ORDER BY.
Attempts:
2 left
💡 Hint
Think about when rows are removed in the process: before or after grouping?
🧠 Conceptual
intermediate
2:00remaining
Understanding HAVING clause filtering
Which statement best describes when the HAVING clause is applied in an SQL query?
AIt filters individual rows before grouping.
BIt filters groups after aggregation is done.
CIt filters columns before SELECT.
DIt filters rows after ORDER BY.
Attempts:
2 left
💡 Hint
Think about filtering groups, not rows.
query_result
advanced
3:00remaining
Output of WHERE vs HAVING filtering
Given the table sales with columns region and amount, what is the output of this query?

SELECT region, SUM(amount) AS total FROM sales WHERE amount > 100 GROUP BY region;
SQL
Table sales:
region | amount
-------|-------
East   | 150
East   | 90
West   | 200
West   | 50
South  | 120
South  | 80
A[{"region": "East", "total": 90}, {"region": "West", "total": 50}, {"region": "South", "total": 80}]
B[{"region": "East", "total": 240}, {"region": "West", "total": 250}, {"region": "South", "total": 200}]
C[{"region": "East", "total": 150}, {"region": "West", "total": 200}, {"region": "South", "total": 120}]
D[{"region": "East", "total": 0}, {"region": "West", "total": 0}, {"region": "South", "total": 0}]
Attempts:
2 left
💡 Hint
Remember WHERE filters rows before grouping.
query_result
advanced
3:00remaining
Output of HAVING filtering after aggregation
Given the same sales table, what is the output of this query?

SELECT region, SUM(amount) AS total FROM sales GROUP BY region HAVING SUM(amount) > 200;
SQL
Table sales:
region | amount
-------|-------
East   | 150
East   | 90
West   | 200
West   | 50
South  | 120
South  | 80
A[{"region": "East", "total": 240}, {"region": "West", "total": 250}]
B[{"region": "East", "total": 240}, {"region": "West", "total": 250}, {"region": "South", "total": 200}]
C[{"region": "South", "total": 200}]
D[]
Attempts:
2 left
💡 Hint
HAVING filters groups after SUM is calculated.
📝 Syntax
expert
2:00remaining
Identify the syntax error in combined WHERE and HAVING query
Which option contains a syntax error in this query?

SELECT region, COUNT(*) FROM sales WHERE region = 'East' HAVING COUNT(*) > 1 GROUP BY region;
AThe COUNT(*) function cannot be used in HAVING.
BThe WHERE clause cannot be used with GROUP BY.
CThe GROUP BY clause must come before HAVING, so this query is correct.
DThe HAVING clause appears before GROUP BY, causing a syntax error.
Attempts:
2 left
💡 Hint
Check the order of clauses in SQL syntax.