0
0
SQLquery~10 mins

GROUP BY multiple columns 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 group the sales by both city and product.

SQL
SELECT city, product, SUM(sales) FROM sales_data GROUP BY [1];
Drag options to blanks, or click blank then click option'
Acity, product
Bcity
Cproduct
Dsales
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by only one column when multiple are needed.
Including aggregated columns in GROUP BY.
2fill in blank
medium

Complete the code to count the number of orders grouped by customer and order_date.

SQL
SELECT customer_id, order_date, COUNT(*) FROM orders GROUP BY [1];
Drag options to blanks, or click blank then click option'
Acustomer_id
Bcustomer_id, order_date
Corder_date
Dorder_id
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by only one column when two are needed.
Grouping by a column not selected.
3fill in blank
hard

Fix the error in the GROUP BY clause to correctly group by both department and role.

SQL
SELECT department, role, AVG(salary) FROM employees GROUP BY [1];
Drag options to blanks, or click blank then click option'
Adepartment role
Bsalary
Crole, department,
Ddepartment, role
Attempts:
3 left
💡 Hint
Common Mistakes
Missing commas between columns.
Including aggregated columns in GROUP BY.
4fill in blank
hard

Fill both blanks to group sales by region and product category.

SQL
SELECT [1], [2], SUM(amount) FROM sales GROUP BY [1], [2];
Drag options to blanks, or click blank then click option'
Aregion
Bamount
Cproduct_category
Ddate
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by columns not selected.
Using aggregated columns in GROUP BY.
5fill in blank
hard

Fill all three blanks to select city, category, and total sales grouped by city and category.

SQL
SELECT [1], [2], SUM([3]) FROM sales_data GROUP BY [1], [2];
Drag options to blanks, or click blank then click option'
Acity
Bcategory
Csales
Ddate
Attempts:
3 left
💡 Hint
Common Mistakes
Grouping by columns not in SELECT.
Using wrong column inside SUM().