AlgoMaster Logo

Exercise: Advanced Grouping

Last Updated: May 12, 2026

1 min read

For this exercise, we will work with below data:

SQL

Exercise 1

Easy

Write a query using ROLLUP on users.country that returns the user count per country plus a grand total row. Order by country with NULLs last.

SQL

Expected Query

Expected Output

Exercise 2

Medium

Write a query using GROUPING SETS that returns subscription counts by plan alone and a grand total. Use the subscriptions table. Order by plan with NULLs last.

SQL

Expected Query

Expected Output