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 the value of an expression representing all rows. Only one expression is specified as a parameter. You can get the average without duplicates by using the DISTINCT or UNIQUE keyword in front of the expression or the average of all values by omitting the keyword or by using ALL.

Syntax

AVG ( [ { DISTINCT | DISTINCTROW } | UNIQUE | ALL ] expression )

  • expression : Specifies an expression that returns a numeric value. A collection expression cannot be specified.
  • ALL : Calculates an average value for all data (default).
  • DISTINCT or UNIQUE : Calculates an average value without duplicates.
Example

The following example shows how to retrieve the average number of gold medals that Korea won in Olympics (demodb).

SELECT AVG(gold)

FROM participant

WHERE nation_code = 'KOR';

Result value : 9