Complete the code to add subtotals using ROLLUP in the GROUP BY clause.
SELECT department, SUM(sales) FROM sales_data GROUP BY [1];In MySQL, to get subtotals using ROLLUP, you add WITH ROLLUP after the column in the GROUP BY clause.
Complete the code to group by two columns and include subtotals with ROLLUP.
SELECT region, department, SUM(sales) FROM sales_data GROUP BY region, [1] WITH ROLLUP;When grouping by multiple columns with ROLLUP, list all columns before WITH ROLLUP. Here, department is the second grouping column.
Fix the error in the GROUP BY clause to correctly use ROLLUP for subtotals.
SELECT category, product, SUM(quantity) FROM inventory GROUP BY category, product [1];The correct syntax to add subtotals is WITH ROLLUP after the GROUP BY columns.
Fill both blanks to group by year and month with subtotals using ROLLUP.
SELECT year, [1], SUM(revenue) FROM financials GROUP BY year, [2] WITH ROLLUP;
To group by year and month with subtotals, use month as the second column in SELECT and GROUP BY.
Fill all three blanks to create subtotals by country, state, and city using ROLLUP.
SELECT [1], [2], city, SUM(population) FROM demographics GROUP BY [3], state, city WITH ROLLUP;
The SELECT columns must match the GROUP BY columns. Here, country and state fill the blanks in SELECT and GROUP BY.