Grouping Sets

Learn and practice grouping sets in PostgreSQL.

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:

Get hands-on with 1200+ tech skills courses.