0
0
SQLquery~10 mins

Why grouping is needed in SQL - Test Your Understanding

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

Complete the code to select the total sales for each product.

SQL
SELECT product_id, SUM(sales) FROM sales_data GROUP BY [1];
Drag options to blanks, or click blank then click option'
Asales
Bproduct_id
Ctotal
Ddate
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by sales instead of product_id.
Not using GROUP BY at all.
2fill in blank
medium

Complete the code to find the average score for each student.

SQL
SELECT student_name, AVG(score) FROM exam_results GROUP BY [1];
Drag options to blanks, or click blank then click option'
Astudent_name
Bclass
Cscore
Dexam_date
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by score instead of student_name.
Forgetting to use GROUP BY.
3fill in blank
hard

Fix the error in the query to get the count of orders per customer.

SQL
SELECT customer_id, COUNT(order_id) FROM orders [1] customer_id;
Drag options to blanks, or click blank then click option'
AORDER BY
BWHERE
CHAVING
DGROUP BY
Attempts:
3 left
💡 Hint
Common Mistakes
Using ORDER BY instead of GROUP BY.
Using WHERE clause incorrectly.
4fill in blank
hard

Fill both blanks to get the total sales and average price per category.

SQL
SELECT category, [1](sales), [2](price) FROM products GROUP BY category;
Drag options to blanks, or click blank then click option'
ASUM
BAVG
CCOUNT
DMAX
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT instead of SUM or AVG.
Mixing up SUM and AVG functions.
5fill in blank
hard

Fill all three blanks to get the number of employees, average salary, and maximum age per department.

SQL
SELECT department, [1](employee_id), [2](salary), [3](age) FROM employees GROUP BY department;
Drag options to blanks, or click blank then click option'
ACOUNT
BAVG
CMAX
DMIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using MIN instead of MAX for age.
Using SUM instead of COUNT for employee count.