0
0
MySQLquery~10 mins

HAVING clause in MySQL - Interactive Code Practice

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

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

MySQL
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 for aggregate filtering.
Using the wrong comparison operator like < instead of >.
2fill in blank
medium

Complete the code to find products with total sales equal to 100 or more.

MySQL
SELECT product_id, SUM(quantity) FROM sales GROUP BY product_id HAVING SUM(quantity) [1] 100;
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 for aggregate conditions.
Using <= instead of >= which filters the wrong groups.
3fill in blank
hard

Fix the error in the code to correctly filter groups with average score above 80.

MySQL
SELECT class, AVG(score) FROM results GROUP BY class HAVING AVG(score) [1] 80;
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 for aggregate filters.
Using < or <= which selects wrong groups.
4fill in blank
hard

Fill both blanks to select customers with total orders more than 10 and total amount less than 500.

MySQL
SELECT customer_id, COUNT(order_id), SUM(amount) FROM orders GROUP BY customer_id HAVING COUNT(order_id) [1] 10 AND SUM(amount) [2] 500;
Drag options to blanks, or click blank then click option'
A>
B<
C<=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up comparison operators.
Using WHERE instead of HAVING for aggregate filters.
5fill in blank
hard

Fill all three blanks to select departments with average salary above 50000, count of employees at least 5, and maximum salary below 100000.

MySQL
SELECT department, AVG(salary), COUNT(*), MAX(salary) FROM employees GROUP BY department HAVING AVG(salary) [1] 50000 AND COUNT(*) [2] 5 AND MAX(salary) [3] 100000;
Drag options to blanks, or click blank then click option'
A>
B>=
C<
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators for the conditions.
Confusing WHERE with HAVING for aggregate filters.