extension produces a hierarchical set of groups with subtotals for each hierarchical group as well as a grand total. The order of the hierarchy is determined by the order of the expressions given in the ROLLUP
expression list. The top of the hierarchy is the leftmost item in the list. Each successive item proceeding to the right moves down the hierarchy with the rightmost item being the lowest level.
| ( expr_2a
] ...) ] ...)
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 grouping level of the hierarchy.
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, within each grouping of the first item and so on. Finally a grand total is returned for the entire result set.
extension specified within the context of the GROUP BY
clause is shown by the following:
The items specified in select_list
must also appear in the ROLLUP 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 ROLLUP
extensions as well as multiple occurrences of other GROUP BY
extensions and individual expressions.
The ORDER BY
clause should be used if you want the output to display in a hierarchical or other meaningful structure. There is no guarantee on the order of the result set if no ORDER BY
clause is specified.