GROUPING SETS, ROLLUP, CUBE

These are advanced grouping functions used to create multiple grouping sets in a single query.

Example: Using ROLLUP

SELECT City, Contribution, SUM(ContributionAmount) AS TotalContribution
FROM FreedomFighters
GROUP BY ROLLUP (City, Contribution);

Output:

Provides totals for each city and contribution, including grand totals.

Notes

  • GROUPING SETS: Specifies multiple groupings explicitly.
  • ROLLUP: Creates hierarchical groupings for subtotals and grand totals.
  • CUBE: Creates all possible groupings for multidimensional analysis.