Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 |  CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

AVG Function

Description

The AVG function calculates the arithmetic average of an expression with a single value. You can use any data type that can be added or divided by a number. The data type of the attribute to be averaged is maintained. For example, if the attribute is a floating point value, the AVG function also returns a FLOAT. You cannot get the average of a collection.

syntax

AVG ( [ DISTINCT | UNIQUE | ALL ] expression )

When calculating the average of a value specified in an expression, you can determine whether to include all instances or only unique values.

  • expression : Specifies the expression to be averaged.
  • ALL : Includes all values to calculate the average (default).
  • DISTINCT or UNIQUE : Includes only unique values to calculate the average.
Example

The following is an example that returns the average number of gold medals that Korea won in the Olympic Games from 1988 to 2004.

SELECT AVG(gold)
FROM participant
WHERE nation_code = 'KOR';

Result : 9