Returns the sum of the values in a group. The keyword DISTINCT specifies that the duplicate values are to be eliminated before computing the sum.

Syntax

SUM ( {[ALL]expression}|{ DISTINCT column_ref} )

Notes

  • The argument column_ref or expression can only be of numeric data type, such as INTEGER, DECIMAL, and so on.
  • The result of the function is of the same data type as that of the argument except that the result is of type INTEGER when the argument is of type SMALLINT or TINYINT.
  • The result can have a NULL value.

Example

This example illustrates the SUM function:

SELECT SUM (amount)
     FROM orders
     WHERE order_date = SYSDATE ;