SUM [Aggregate]
Computes the sum of an expression over a group of rows. SUM
returns a DOUBLE PRECISION
value for a floating-point expression. Otherwise, the return value is the same as the expression data type.
The SUM
aggregate function differs from the SUM
analytic function, which computes the sum of an expression over a group of rows within a window.
Behavior Type
Syntax
SUM ( [ ALL | DISTINCT ] expression )
Parameters
ALL
|
Invokes the aggregate function for all rows in the group (default) |
DISTINCT
|
Invokes the aggregate function for all distinct non-null values of the expression found in the group |
expression |
Any |
Overflow Handling
If you encounter data overflow when using SUM()
, use SUM_FLOAT
which converts the data to a floating point.
By default, Vertica allows silent numeric overflow when you call this function on numeric data types. For more information on this behavior and how to change it, see Numeric Data Type Overflow with SUM, SUM_FLOAT, and AVG.
Example
The following query returns the total sum of the product_cost
column.
=> SELECT SUM(product_cost) AS cost FROM product_dimension; cost --------- 9042850 (1 row)