Grouping Sets
Explore how to efficiently compute aggregates for multiple groupings in a single SQL query using grouping sets, rollup, and cube clauses. This lesson helps you understand their syntax and practical applications, enabling hierarchical and multidimensional data summarization.
We'll cover the following...
There is a restriction that comes with using classic aggregates—we can only run them through a single group definition at a time. In some cases, we want to be able to compute aggregates for several groups in parallel. For those cases, SQL provides the grouping sets feature.
In the Formula One competition, points are given to drivers and then used to compute both the driver’s champion and the constructor’s champion points. Can we compute those two sums over the same points in a single query? Yes, of course, we can:
We see that we get null entries for drivers when the aggregate has been computed for a constructor’s group and null entries for constructors when ...