SUM

Given a set of numeric values, SUM returns the total of all values in the input set.

Syntax

SUM (expression)

Remarks

The expression is a numeric expression.
SUM works only with numeric data types and data types that can be converted to numeric.
The sum of a table with empty rows or no rows is NULL.
See About SQL Functions in TDV for an explanation of the DECIMAL(p,s) notation.

The following table lists the input types that you can use in SUM, and their corresponding INTEGER output types.

Data Type of expression

Output Type

BIGINT, DOUBLE, INTERVAL_DAY, INTERVAL_YEAR, SMALLINT, TINYINT

BIGINT

VARCHAR

DECIMAL(41,2)

FLOAT, REAL

FLOAT

DECIMAL(p,s), NUMERIC(p,s)

DECIMAL (p+6, s)
For example, the output of SUM(DECIMAL (4, 2) would be SUM(DECIMAL (10, 2)

NULL

NULL

Example

SELECT SUM (products.UnitPrice) Total 
FROM /shared/examples/ds_inventory/products products