Book Contents

Book Index

Next Topic

Home

Aggregate Expressions

An aggregate expression represents the application of an aggregate function across the rows or groups of rows selected by a query. The syntax of an aggregate expression is one of the following (using AVG as an example):

AVG (expression)

invokes the aggregate across all input rows for which the given expression yields a non-null value.

AVG (ALL expression)

is the same as AVG(expression), since ALL is the default.

AVG (DISTINCT expression)

invokes the AVG function across all input rows for all distinct, non-null values of the expression.

where expression is any value expression that does not itself contain an aggregate expression.

An aggregate expression only can appear in the select list or HAVING clause of a SELECT statement. It is forbidden in other clauses, such as WHERE, because those clauses are evaluated before the results of aggregates are formed.