Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by sales instead of product_id.
Not using GROUP BY at all.
✗ Incorrect
Grouping by product_id allows us to calculate the total sales per product.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by score instead of student_name.
Forgetting to use GROUP BY.
✗ Incorrect
Grouping by student_name lets us calculate the average score per student.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ORDER BY instead of GROUP BY.
Using WHERE clause incorrectly.
✗ Incorrect
The GROUP BY clause groups rows by customer_id so COUNT counts orders per customer.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT instead of SUM or AVG.
Mixing up SUM and AVG functions.
✗ Incorrect
Use SUM to add sales and AVG to find average price per category.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using MIN instead of MAX for age.
Using SUM instead of COUNT for employee count.
✗ Incorrect
Use COUNT to count employees, AVG for average salary, and MAX for maximum age per department.