DB2 graphic  QMF Version 8

AVG

AVG is a column function. The following example includes more than one column function in the SELECT statement. For Department 10, it calculates and displays the sum of employee salaries, the minimum, average, and maximum salary, and the number of employees (COUNT) in the department.

This query:

SELECT SUM(SALARY), MIN(SALARY), AVG(SALARY),
   MAX(SALARY), COUNT(*)
FROM Q.STAFF
WHERE DEPT = 10

Produces this report:

SUM(SALARY) MIN(SALARY)      AVG(SALARY) MAX(SALARY) COUNT(EXPRESSION)
----------- ----------- ---------------- ----------- -----------------
   83463.45    19260.25 20865.8625000000    22959.20                 4

Write a column function like this:

AVG(expression)

The parentheses are required. expression is most often a column name, but can also be:

A column name in a function must not refer to a long string column or a column derived from a column function (a column of a view can be derived from a function). Column functions cannot be nested within other column functions. Null values are not included in the calculation made by a column function.


Go to the previous page Go to the next page

Downloads | Library | Support | Support Policy | Terms of use | Feedback
Copyright IBM Corporation 1982,2004 Copyright IBM Corporation 1982, 2004
timestamp Last updated: March, 2004