SUM( )

From InterBase
Jump to: navigation, search

Go Up to Statement and Function Reference (Language Reference Guide)


Totals the numeric values in a specified column. Available in gpre, DSQL, and isql.

SUM ([ALL] val | DISTINCT val)
Argument Description

ALL

Totals all values in a column

DISTINCT

Eliminates duplicate values before calculating the total

<val>

A column, constant, host-language variable, expression, non-aggregate function, or UDF that evaluates to a numeric data type

Description: SUM() is an aggregate function that calculates the sum of numeric values for a column. If the number of qualifying rows is zero, SUM() returns a NULL value.

Example: The following embedded SQL statement demonstrates the use of SUM(), AVG(), MIN(), and MAX():

EXEC SQL
SELECT SUM (BUDGET), AVG (BUDGET), MIN (BUDGET), MAX (BUDGET)
FROM DEPARTMENT
WHERE HEAD_DEPT = :head_dept
INTO :tot_budget, :avg_budget, :min_budget, :max_budget;

See Also