Aggregate functions
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).
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 a single aggregate of an expression. For example SUM(x) + SUM(y)
can be expressed as as SUM(x+y)
if neither argument is NULL.
Vertica does not support nested aggregate functions.
You can use some of the simple aggregate functions as analytic (window) functions. See Analytic functions for details. See also SQL analytics.
Some collection functions also behave as aggregate functions.
Note
All functions in this section that have an analytic function counterpart are appended with [aggregate] to avoid confusion between the two.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]
- TS_FIRST_VALUE
- TS_LAST_VALUE
- VAR_POP [aggregate]
- VAR_SAMP [aggregate]
- VARIANCE [aggregate]
- WITHIN GROUP ORDER BY clause