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 | 

SUM Function

Description

The SUM function returns the sum of the values in expression. Numeric data types with the addition operator can also be calculated by the SUM function. String data types as well as SET, MULTISET and LIST (SEQUENCE) types cannot be calculated by the SUM function; they can be concatenated with the + operator. In addition, the SUM function cannot be used for expressions that contain attributes with object domains (user-defined classes or multimedia classes).

Syntax

SUM ( [ DISTINCT | UNIQUE | ALL ] expression )

With the input for the SUM function, you can specify a single-value expression.

  • expression : Specifies the expression to calculate the sum.
  • ALL : Gets the sum of all instances of the expression (default).
  • DISTINCT or UNIQUE : Gets the sum of unique values without duplicates.
Example

The following is an example that returns the total number of gold medals in the 1998 Olympics.

SELECT SUM(gold)
FROM participant
WHERE host_year = 1988;

Result : 241