Aggregate functions calculate a single value for a collection of
rows in a result table. Aggregate functions are sometimes called
statistical functions.
The following notes generally apply to aggregate functions. An
aggregate function is a single value derived from one or more
sets of values.
o A value expression is used to evaluate a value for each row.
The aggregate function operates on these values.
o Null values are not included when SQL evaluates functions. If
you specify DISTINCT, redundant values are also not included.
If you have set the dialect to SQL99, this null elimination
causes a warning to be returned for the SQLCODE or SQLSTATE.
See the Oracle Rdb SQL Reference Manual for more information
on SQLSTATE and SQLCODE.
o If a function has as its argument a value expression that
contains a column name that is an outer reference (see Outer_
References), the value expression cannot include an arithmetic
operator. (The only cases where an outer reference makes sense
as the argument to a function is in the subquery of a HAVING
clause or in a subquery in a select list.)
o You cannot nest functions. This means that a value expression
used as an argument to a function cannot include a function.
o The keyword ALL in SUM, AVG, MAX, and MIN has no effect. For
instance, specifying MAX (ALL EMPLOYEE_ID) is the same as
saying MAX (EMPLOYEE_ID).
o VARIANCE and STDDEV must be passed a single numeric value
expression and the result is returned as a DOUBLE PRECISION
value. Use the CAST function to alter the result data type.
o VARIANCE, and hence STDDEV, assume that one degree of freedom
is used in the calculation of the mean (average) and therefore
the divisor is specified as (n-1). For a large number of
values in the statistical sample this will not be significant.
However, for small samples it may not be desirable, so this
default can be changed for the current session by using the
SET FLAGS option VARIANCE_DOF(0). Only the values 0 and 1 are
allowed.
o The keywords ALL and DISTINCT are not permitted when using
the VAR_POP, VAR_SAMP, STDDEV_POP and STDDEV_SAMP statistical
functions.
The FILTER clause is provided for all statistical functions. This
clause can be used to limit the values included in the COUNT,
MAX, MIN, SUM, AVG, STDDEV, and VARIANCE functions.
FILTER can be used to eliminate data from the statistical
function so that the generated report can process the data in
a single pass. The following example illustrates how the FILTER
clause is applied.
SQL> select
cont> max (salary_amount) filter (where salary_end is null),
cont> max (salary_amount) filter (where salary_end is not null),
cont> min (distinct salary_amount) filter (where salary_end = salary_start),
cont> min (distinct salary_amount) filter (where salary_end > salary_start)
cont> from
cont> salary_history
cont> where
cont> employee_id = '00164'
cont> group by
cont> employee_id;
51712.00 50000.00 NULL 26291.00
1 row selected
SQL>
Additional Information:
explode
extract