0
0
SQLquery~10 mins

WHERE vs HAVING mental model in SQL - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to filter rows where the age is greater than 30.

SQL
SELECT * FROM employees WHERE age [1] 30;
Drag options to blanks, or click blank then click option'
A<=
B<
C=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will select younger employees.
Using '=' will only select employees exactly 30 years old.
2fill in blank
medium

Complete the code to show departments having more than 5 employees.

SQL
SELECT department, COUNT(*) FROM employees GROUP BY department HAVING COUNT(*) [1] 5;
Drag options to blanks, or click blank then click option'
A>
B<=
C=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using WHERE instead of HAVING to filter aggregated results.
Using '<=' will select departments with 5 or fewer employees.
3fill in blank
hard

Fix the error in the query to filter employees with salary above 50000 after grouping by department.

SQL
SELECT department, AVG(salary) FROM employees GROUP BY department HAVING AVG(salary) [1] 50000;
Drag options to blanks, or click blank then click option'
AWHERE
B>
CHAVING
DGROUP BY
Attempts:
3 left
💡 Hint
Common Mistakes
Using WHERE to filter aggregated results causes syntax errors.
Placing HAVING before GROUP BY is incorrect.
4fill in blank
hard

Fill both blanks to filter products with price greater than 100 and groups having total quantity sold more than 50.

SQL
SELECT product_id, SUM(quantity) FROM sales WHERE price [1] 100 GROUP BY product_id HAVING SUM(quantity) [2] 50;
Drag options to blanks, or click blank then click option'
A>
B<
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' changes the filter logic.
Using WHERE instead of HAVING for aggregated filters.
5fill in blank
hard

Fill all three blanks to select customers with age over 25, group by city, and only show cities with more than 10 customers.

SQL
SELECT city, COUNT(*) FROM customers WHERE age [1] 25 GROUP BY [2] HAVING COUNT(*) [3] 10;
Drag options to blanks, or click blank then click option'
A>
Bcity
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using age in GROUP BY instead of city.
Using WHERE to filter aggregated counts.