Creating multilevel totals with aggregate functions might not be the first thing you think about. This has been a capability of the aggregate functionality for quite some time.
The purpose of the GROUP BY
clause is to group rows together, based on the columns specified. But with aggregates, you don't always need to specify columns. When you want a grand total, you can omit the GROUP BY
clause altogether:
Omitting the GROUP BY
clause leads to a grand total, but you can also use an empty set in the GROUP BY
clause:
On line 3 the empty set is used, denoted by the opening and closing braces ()
.
There is a lot more about aggregates, such as GROUPING SETS
, ROLLUP
, and CUBE
.
In the preceding example, we created a grand total by using an empty set in the GROUP BY
clause. The GROUPING SETS
clause...