FirebirdSQL logo

SUM()

Sum

Result type

Depends on the input type

Syntax
SUM ([ALL | DISTINCT] <expr>)
Table 1. SUM Function Parameters
Parameter Description

expr

Numeric expression.It may contain a table column, a constant, a variable, an expression, a non-aggregate function or a UDF.Aggregate functions are not allowed as expressions.

SUM calculates and returns the sum of non-NULL values in the group.

  • If the group is empty or contains only NULLs, the result is NULL.

  • ALL is the default option — all values in the set that are not NULL are processed.If DISTINCT is specified, duplicates are removed from the set and the SUM evaluation is done afterwards.

The result type of SUM depends on the input type:

FLOAT, DOUBLE PRECISION

DOUBLE PRECISION

SMALLINT, INTEGER

BIGINT

BIGINT, INT128

INT128

DECIMAL/NUMERIC(p, n) with p < 10

DECIMAL/NUMERIC(18, n)

DECIMAL/NUMERIC(p, n) with p >= 10

DECIMAL/NUMERIC(38, n)

DECFLOAT(16), DECFLOAT(34)

DECFLOAT(34)

SUM Examples

SELECT
  dept_no,
  SUM (salary),
FROM employee
GROUP BY dept_no
See also

SELECT