Chapter 3. DB2 UDB’s statistics, analytic, and OLAP functions 125
? FOLLOWING specifies either the range or number of rows following the
current row as being in the window. If ROWS is specified, then
value
is a
positive integer indicating a number of rows. If RANGE is specified, then the
data type of
value
must be comparable to the type of the sort-key-expression
of the window ORDER BY clause.
3.3.2 GROUPING capabilities ROLLUP & CUBE
The result of a GROUP BY operation is a set of groups of rows. Each row in this
result represents the set of rows for which the grouping-expression is satisfied.
Complex forms of the GROUP BY clause include grouping-sets and
super-groups.
Figure 3-7 GROUP BY clause
A grouping sets specification allows multiple grouping clauses to be specified in a
single statement. This can be thought of as a union of two or more groups of
rows into a single result set. It is logically equivalent to the union of multiple
subselects with the group by clause in each subselect corresponding to one
grouping set. A grouping set can be a single element, or can be a list of elements
delimited by parentheses, where an element is either a grouping expression, or a
super-group.
GROUP BY a is equivalent to GROUP BY GROUPING SETS ((a))
GROUP BY a,b,c is equivalent to GROUP BY GROUPING SETS ((a,b,c))
In terms of OLAP functions we will confine our discussion to the two
super-groups ROLLUP and CUBE, whose syntax is shown in Figure 3-8.
Note: For grouping, all null values from a
grouping-expression
are considered
equal.