SQL practice: GROUPING SETS, ROLLUP and CUBE

Chapter 43 · 5 questions · included in full access

  1. Question 1 · easy

    Count 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.

    Solve it in your browser
  2. Question 2 · easy

    Write 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.

    Solve it in your browser
  3. Question 3 · medium

    Produce 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.

    Solve it in your browser
  4. Question 4 · hard

    Count 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.

    Solve it in your browser
  5. Question 5 · hard

    You 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?

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing