0
0
MySQLquery~10 mins

ROLLUP for subtotals in MySQL - Interactive Code Practice

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

Complete the code to add subtotals using ROLLUP in the GROUP BY clause.

MySQL
SELECT department, SUM(sales) FROM sales_data GROUP BY [1];
Drag options to blanks, or click blank then click option'
Adepartment WITH ROLLUP
Bdepartment ROLLUP
Cdepartment, ROLLUP
Ddepartment WITH ROLLUP()
Attempts:
3 left
💡 Hint
Common Mistakes
Using ROLLUP without WITH keyword
Adding parentheses after ROLLUP
Separating ROLLUP with a comma
2fill in blank
medium

Complete the code to group by two columns and include subtotals with ROLLUP.

MySQL
SELECT region, department, SUM(sales) FROM sales_data GROUP BY region, [1] WITH ROLLUP;
Drag options to blanks, or click blank then click option'
Atotal
Bregion
Csales
Ddepartment
Attempts:
3 left
💡 Hint
Common Mistakes
Using sales or total as grouping columns
Omitting the second grouping column
3fill in blank
hard

Fix the error in the GROUP BY clause to correctly use ROLLUP for subtotals.

MySQL
SELECT category, product, SUM(quantity) FROM inventory GROUP BY category, product [1];
Drag options to blanks, or click blank then click option'
AROLLUP
BGROUP ROLLUP
CWITH ROLLUP
DBY ROLLUP
Attempts:
3 left
💡 Hint
Common Mistakes
Using only ROLLUP without WITH
Adding GROUP or BY keywords before ROLLUP
4fill in blank
hard

Fill both blanks to group by year and month with subtotals using ROLLUP.

MySQL
SELECT year, [1], SUM(revenue) FROM financials GROUP BY year, [2] WITH ROLLUP;
Drag options to blanks, or click blank then click option'
Amonth
Bquarter
Dday
Attempts:
3 left
💡 Hint
Common Mistakes
Using quarter or day instead of month
Mismatching SELECT and GROUP BY columns
5fill in blank
hard

Fill all three blanks to create subtotals by country, state, and city using ROLLUP.

MySQL
SELECT [1], [2], city, SUM(population) FROM demographics GROUP BY [3], state, city WITH ROLLUP;
Drag options to blanks, or click blank then click option'
Acountry
Bstate
Dcity
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching SELECT and GROUP BY columns
Using city in blanks where country or state is needed