0
0
MySQLquery~5 mins

ROLLUP for subtotals in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the ROLLUP operator do in a SQL query?
ROLLUP adds extra rows to the result set that show subtotals and a grand total for grouped data.
Click to reveal answer
intermediate
How does ROLLUP affect the GROUP BY clause?
ROLLUP extends GROUP BY by creating grouping sets that include all levels of aggregation from detailed groups up to a grand total.
Click to reveal answer
beginner
In MySQL, what value appears in the ROLLUP subtotal rows for the grouped columns?
The grouped columns in subtotal rows show NULL to indicate aggregation over all values in that column.
Click to reveal answer
beginner
Write a simple SQL query using ROLLUP to get sales totals by region and product.
SELECT region, product, SUM(sales) AS total_sales FROM sales_table GROUP BY region, product WITH ROLLUP;
Click to reveal answer
beginner
Why is ROLLUP useful in reports?
ROLLUP helps create reports that show detailed data plus subtotals and grand totals in one query, saving extra calculations.
Click to reveal answer
What does the ROLLUP operator add to a GROUP BY query?
AOnly detailed rows
BOnly grand total row
CSubtotals and grand totals
DNo additional rows
In a ROLLUP result, what does a NULL value in a grouped column mean?
AMissing data
BError in query
CNo rows matched
DSubtotal or total for that column
Which SQL clause is extended by ROLLUP?
AGROUP BY
BWHERE
CORDER BY
DHAVING
What keyword is used in MySQL to enable ROLLUP?
AWITH ROLLUP
BROLLUP ON
CGROUP BY ROLLUP
DROLLUP ENABLE
If you GROUP BY region, product WITH ROLLUP, which row is NOT included?
ASubtotal by region
BSubtotal by product
CGrand total
DDetailed rows by region and product
Explain how the ROLLUP operator works in SQL and why it is useful for generating subtotals and totals.
Think about how ROLLUP adds extra rows to grouped results.
You got /4 concepts.
    Write a SQL query using ROLLUP to show sales totals by two categories and explain the output rows you expect.
    Use GROUP BY with two columns and WITH ROLLUP.
    You got /4 concepts.