0
0
SQLquery~10 mins

GROUP BY with aggregate functions 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 find the total sales for each product.

SQL
SELECT product_id, SUM([1]) FROM sales GROUP BY product_id;
Drag options to blanks, or click blank then click option'
Aquantity
Bprice
Cdiscount
Ddate
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a non-numeric column like 'date' causes errors.
Using 'price' sums prices, not quantities sold.
2fill in blank
medium

Complete the code to count how many orders each customer made.

SQL
SELECT customer_id, COUNT([1]) FROM orders GROUP BY customer_id;
Drag options to blanks, or click blank then click option'
Acustomer_name
Btotal_amount
Corder_date
Dorder_id
Attempts:
3 left
💡 Hint
Common Mistakes
Counting 'customer_name' counts duplicates incorrectly.
Counting 'total_amount' might miss orders with null amounts.
3fill in blank
hard

Fix the error in the query to find the average price per category.

SQL
SELECT category, AVG([1]) FROM products GROUP BY category;
Drag options to blanks, or click blank then click option'
Acategory
Bprice
Cproduct_name
Dstock
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-numeric column inside AVG causes errors.
Not grouping by category would cause incorrect results.
4fill in blank
hard

Fill both blanks to find the maximum and minimum order amounts per customer.

SQL
SELECT customer_id, [1](order_amount), [2](order_amount) FROM orders GROUP BY customer_id;
Drag options to blanks, or click blank then click option'
AMAX
BMIN
CSUM
DCOUNT
Attempts:
3 left
💡 Hint
Common Mistakes
Using SUM or COUNT instead of MAX or MIN changes the meaning.
Mixing up MAX and MIN order.
5fill in blank
hard

Fill all three blanks to find the average, total, and count of sales per region.

SQL
SELECT region, [1](sales_amount), [2](sales_amount), [3](sales_amount) FROM sales_data GROUP BY region;
Drag options to blanks, or click blank then click option'
AAVG
BSUM
CCOUNT
DMAX
Attempts:
3 left
💡 Hint
Common Mistakes
Using MAX instead of COUNT changes the meaning.
Mixing the order of aggregate functions.