0
0
SQLquery~10 mins

HAVING clause for filtering groups in SQL - Interactive Code Practice

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

Complete the code to filter groups having more than 3 orders.

SQL
SELECT customer_id, COUNT(*) FROM orders GROUP BY customer_id HAVING COUNT(*) [1] 3;
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 filtering groups
Using < instead of > in the HAVING clause
2fill in blank
medium

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

SQL
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
Using < instead of >= in HAVING
3fill in blank
hard

Fix the error in the HAVING clause to filter groups with average price less than 50.

SQL
SELECT category, AVG(price) FROM products GROUP BY category HAVING AVG(price) [1] 50;
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
Using > instead of < in HAVING
4fill in blank
hard

Fill both blanks to select customers with more than 5 orders and total amount over 1000.

SQL
SELECT customer_id, COUNT(*), SUM(amount) FROM orders GROUP BY customer_id HAVING COUNT(*) [1] 5 AND SUM(amount) [2] 1000;
Drag options to blanks, or click blank then click option'
A>
B<
C>=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > in conditions
Using WHERE instead of HAVING
5fill in blank
hard

Fill all three blanks to select products with average rating above 4, total reviews at least 50, and total sales over 200.

SQL
SELECT product_id, AVG(rating), COUNT(review_id), SUM(sales) FROM product_reviews GROUP BY product_id HAVING AVG(rating) [1] 4 AND COUNT(review_id) [2] 50 AND SUM(sales) [3] 200;
Drag options to blanks, or click blank then click option'
A>
B>=
C<
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using < or <= instead of > or ≥
Mixing WHERE and HAVING clauses