Databases Reference
In-Depth Information
This query can be written with the
GROUPING SETS
clause as follows:
As you can see in lines 6 through 11, with the
GROUPING SETS
clause you have more
granular control, but it can be quite verbose. The
Cube
clause is compacter and
processes equivalent results.
Identifying the totals and subtotals with grouping
In the result sets you might notice that it can be confusing to detect which rows in
the result set are the aggregated records and which are not. Oracle did recognize the
need to identify the aggregated records and created some support functions to do so.
These functions are
Grouping
,
Grouping_id
, and
Group_id
.