extension is similar to the ROLLUP
extension. However, unlike ROLLUP
, which produces groupings and results in a hierarchy based on a left to right listing of items in the ROLLUP
expression list, a CUBE
produces groupings and subtotals based on every permutation of all items in the CUBE
expression list. Thus, the result set contains more rows than a ROLLUP
performed on the same expression list.
is an expression that determines the grouping of the result set. If enclosed within parenthesis as ( expr_1a, expr_1b, ...)
then the combination of values returned by expr_1a
defines a single group.
In addition, a subtotal is returned for the first item in the list (expr_1
or the combination of ( expr_1a, expr_1b, ...)
, whichever is specified) for each unique value. A subtotal is returned for the second item in the list (expr_2
or the combination of ( expr_2a, expr_2b, ...)
, whichever is specified) for each unique value. A subtotal is also returned for each unique combination of the first item and the second item. Similarly, if there is a third item, a subtotal is returned for each unique value of the third item, each unique value of the third item and first item combination, each unique value of the third item and second item combination, and each unique value of the third item, second item, and first item combination. Finally a grand total is returned for the entire result set.
The items specified in select_list
must also appear in the CUBE expression_list
; or they must be aggregate functions such as COUNT
, or MAX
; or they must be constants or functions whose return values are independent of the individual rows in the group (for example, the SYSDATE
The GROUP BY
clause may specify multiple CUBE
extensions as well as multiple occurrences of other GROUP BY
extensions and individual expressions.