Previous Topic: Column FunctionsNext Topic: Rules for Column Functions


Description

AVG

Specifies to return the average of the values in the column or expression. The values must be numeric.

SUM

Specifies to return the sum of the values in the column or expression. The values must be numeric.

MAX

Specifies to return the largest value in the column or expression.

MIN

Specifies to return the smallest value in the column or expression.

ALL

Specifies that duplicate values are not to be eliminated before the column function is applied. ALL is the default.

expression

Enter the expression which is to be the argument of the column function. An expression in a column function must include a column name (see the following rules). For more information about expressions, see Expressions.

DISTINCT

Specifies that duplicate values are to be eliminated before the column function is applied.

column-name

Specifies the column which is the argument of the column function.

COUNT(*)

Specifies to count all rows in the result table without eliminating duplicates.

When COUNT(*) is the only item in the SELECT list and there is no join or WHERE clause, an optimization is used to take the count from the CXX rather than actually count the lines in the table. The potential exists for the CXX row count to be incorrect if the MUF has abended at a point where the latest CXX row count is only in memory, but this is an unlikely occurrence and the margin of error is small. In addition, actually counting the rows could potentially be off if inserts or deletes were issued after the count was begun. This enhancement provides a valuable and significant improvement in performance.

If the most accurate count is required, a column can be added to the SELECT list, or a WHERE clause could be added, for example, WHERE 1=1 would be sufficient.

Example 1: CXX Count Returned

SELECT COUNT(*) FROM SYSADM.AGGREGATE;

Example 2: Count each row in table

SELECT COUNT(*) FROM SYSADM.AGGREGATE WHERE 1 = 1;

Note: The CXX count could be inaccurate if MUF has abnormally terminated.

COUNT(DISTINCT column-name)

Specifies to return the number of distinct values of the named column.