Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

SUM() - Calculate sum

Function group: aggregate function

SUM() calculates the sum of all the values in a set. NULL values are ignored.


SUM ([ALL | DISTINCT ] expression )



ALL

All values are taken into account, including duplicate value.


DISTINCT

Only unique values are taken into account. Duplicate values are ignored.


expression

Numeric expression (see section "Aggregate functions" for information on restrictions).


Result

If the set of values returned by expression is empty, the result or the result for this group is the NULL value.

Otherwise:

Without GROUP BY clause:

Calculates the sum of the values returned by expression(see "Calculating aggregate functions").

With GROUP BY clause:

Returns the sum of the values in the derived column of each group.


Data type: like expression with the following number of digits:

Integer or fixed-point number:

The total number of significant digits is 31, the number of digits to the right of the decimal point remains the same.

Floating-point number:

The total number of significant digits corresponds to 21 binary digits for REAL numbers and 53 for DOUBLE PRECISION.

If the sum of the values is too large for this data type, an error message is issued.


Example

Calculate the sum of the parts for each item number in the PURPOSE table:

SELECT item_num, SUM(number) FROM purpose GROUP BY item_num
   item_num
     1         4
   120        27
   200        20