SQL practice: GROUPING SETS, ROLLUP and CUBE
Chapter 43 · 5 questions · included in full access
Question 1 · easy
Solve it in your browserCount orders per region and per city, with a subtotal per region and a grand total, using GROUPING SETS. Show region, city and orders, ordered by region then city with NULLs last. Include branches with no orders.
Question 2 · easy
Solve it in your browserWrite the same report using ROLLUP instead of an explicit GROUPING SETS list. Show region, city and orders, ordered by region then city with NULLs last.
Question 3 · medium
Solve it in your browserProduce every combination of region and customer_type counts for orders, using CUBE over the branch region and the customer type. Show region, customer_type and orders, ordered by region then customer_type with NULLs last.
Question 4 · hard
Solve it in your browserCount orders per region with a grand total, and label the total row 'ALL REGIONS' instead of leaving it NULL. Show region and orders, with the total last.
Question 5 · hard
Solve it in your browserYou run GROUP BY ROLLUP (region, city) over a table where one row has a genuinely NULL city. How do you tell that row apart from the region subtotal, which also shows NULL for city?
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing