Aggregate functions
Note
All functions in this section that have an analytic function counterpart are appended with [Aggregate] to avoid confusion between the two.Aggregate functions summarize data over groups of rows from a query result set. The groups are specified using the GROUP BY clause. They are allowed only in the select list and in the HAVING and ORDER BY clauses of a SELECT statement (as described in Aggregate expressions).
Notes
-
Except for COUNT, these functions return a null value when no rows are selected. In particular, SUM of no rows returns NULL, not zero.
-
In some cases you can replace an expression that includes multiple aggregates with an single aggregate of an expression. For example SUM(x) + SUM(y) can be expressed as as SUM(x+y) (where x and y are NOT NULL).
-
Vertica does not support nested aggregate functions.
You can also use some of the simple aggregate functions as analytic (window) functions. See Analytic functions for details. See also SQL analytics.
In this section
- APPROXIMATE_COUNT_DISTINCT
- APPROXIMATE_COUNT_DISTINCT_OF_SYNOPSIS
- APPROXIMATE_COUNT_DISTINCT_SYNOPSIS
- APPROXIMATE_COUNT_DISTINCT_SYNOPSIS_MERGE
- APPROXIMATE_MEDIAN [aggregate]
- APPROXIMATE_PERCENTILE [aggregate]
- APPROXIMATE_QUANTILES
- ARGMAX_AGG
- ARGMIN_AGG
- AVG [aggregate]
- BIT_AND
- BIT_OR
- BIT_XOR
- BOOL_AND [aggregate]
- BOOL_OR [aggregate]
- BOOL_XOR [aggregate]
- CORR
- COUNT [aggregate]
- COVAR_POP
- COVAR_SAMP
- GROUP_ID
- GROUPING
- GROUPING_ID
- LISTAGG
- MAX [aggregate]
- MIN [aggregate]
- REGR_AVGX
- REGR_AVGY
- REGR_COUNT
- REGR_INTERCEPT
- REGR_R2
- REGR_SLOPE
- REGR_SXX
- REGR_SXY
- REGR_SYY
- STDDEV [aggregate]
- STDDEV_POP [aggregate]
- STDDEV_SAMP [aggregate]
- SUM [aggregate]
- SUM_FLOAT [aggregate]
- VAR_POP [aggregate]
- VAR_SAMP [aggregate]
- VARIANCE [aggregate]
- WITHIN GROUP ORDER BY clause