> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Aggregate functions

> Spark aggregate functions supported in SparkSQL and Databricks compatibility modes.

Preview

Spark [aggregate functions](https://spark.apache.org/docs/latest/sql-ref-functions-builtin.html#aggregate-functions) in [SparkSQL and Databricks compatibility modes](https://docs.firebolt.io/reference-sql/spark/overview.md). Both modes share these functions. Support is one of: Supported, With limitations, or Not supported. Supported means every example in the Spark reference returns what Spark returns; a note under With limitations quotes a call that differs.

| Function | Support | Notes |
| :- | :- | :- |
| [`ANY`](https://spark.apache.org/docs/4.1.0/api/sql/#any) | Supported | |
| [`APPROX_COUNT_DISTINCT`](https://spark.apache.org/docs/4.1.0/api/sql/#approx_count_distinct) | Supported | |
| [`ARRAY_AGG`](https://spark.apache.org/docs/4.1.0/api/sql/#array_agg) | Supported | |
| [`AVG`](https://spark.apache.org/docs/4.1.0/api/sql/#avg) | Supported | |
| [`BIT_AND`](https://spark.apache.org/docs/4.1.0/api/sql/#bit_and) | Supported | |
| [`BIT_OR`](https://spark.apache.org/docs/4.1.0/api/sql/#bit_or) | Supported | |
| [`BIT_XOR`](https://spark.apache.org/docs/4.1.0/api/sql/#bit_xor) | Supported | |
| [`BOOL_AND`](https://spark.apache.org/docs/4.1.0/api/sql/#bool_and) | Supported | |
| [`BOOL_OR`](https://spark.apache.org/docs/4.1.0/api/sql/#bool_or) | Supported | |
| [`COLLECT_LIST`](https://spark.apache.org/docs/4.1.0/api/sql/#collect_list) | Supported | |
| [`CORR`](https://spark.apache.org/docs/4.1.0/api/sql/#corr) | Supported | |
| [`COUNT`](https://spark.apache.org/docs/4.1.0/api/sql/#count) | Supported | |
| [`COUNT_IF`](https://spark.apache.org/docs/4.1.0/api/sql/#count_if) | Supported | |
| [`COVAR_POP`](https://spark.apache.org/docs/4.1.0/api/sql/#covar_pop) | Supported | |
| [`COVAR_SAMP`](https://spark.apache.org/docs/4.1.0/api/sql/#covar_samp) | Supported | |
| [`EVERY`](https://spark.apache.org/docs/4.1.0/api/sql/#every) | Supported | |
| [`MAX`](https://spark.apache.org/docs/4.1.0/api/sql/#max) | Supported | |
| [`MAX_BY`](https://spark.apache.org/docs/4.1.0/api/sql/#max_by) | Supported | |
| [`MEAN`](https://spark.apache.org/docs/4.1.0/api/sql/#mean) | Supported | |
| [`MIN`](https://spark.apache.org/docs/4.1.0/api/sql/#min) | Supported | |
| [`MIN_BY`](https://spark.apache.org/docs/4.1.0/api/sql/#min_by) | Supported | |
| [`REGR_AVGX`](https://spark.apache.org/docs/4.1.0/api/sql/#regr_avgx) | Supported | |
| [`REGR_AVGY`](https://spark.apache.org/docs/4.1.0/api/sql/#regr_avgy) | Supported | |
| [`REGR_COUNT`](https://spark.apache.org/docs/4.1.0/api/sql/#regr_count) | Supported | |
| [`REGR_INTERCEPT`](https://spark.apache.org/docs/4.1.0/api/sql/#regr_intercept) | Supported | |
| [`REGR_R2`](https://spark.apache.org/docs/4.1.0/api/sql/#regr_r2) | Supported | |
| [`REGR_SLOPE`](https://spark.apache.org/docs/4.1.0/api/sql/#regr_slope) | Supported | |
| [`REGR_SXX`](https://spark.apache.org/docs/4.1.0/api/sql/#regr_sxx) | Supported | |
| [`REGR_SXY`](https://spark.apache.org/docs/4.1.0/api/sql/#regr_sxy) | Supported | |
| [`REGR_SYY`](https://spark.apache.org/docs/4.1.0/api/sql/#regr_syy) | Supported | |
| [`SOME`](https://spark.apache.org/docs/4.1.0/api/sql/#some) | Supported | |
| [`STD`](https://spark.apache.org/docs/4.1.0/api/sql/#std) | Supported | |
| [`STDDEV`](https://spark.apache.org/docs/4.1.0/api/sql/#stddev) | Supported | |
| [`STDDEV_POP`](https://spark.apache.org/docs/4.1.0/api/sql/#stddev_pop) | Supported | |
| [`STDDEV_SAMP`](https://spark.apache.org/docs/4.1.0/api/sql/#stddev_samp) | Supported | |
| [`VAR_POP`](https://spark.apache.org/docs/4.1.0/api/sql/#var_pop) | Supported | |
| [`VAR_SAMP`](https://spark.apache.org/docs/4.1.0/api/sql/#var_samp) | Supported | |
| [`VARIANCE`](https://spark.apache.org/docs/4.1.0/api/sql/#variance) | Supported | |
| [`ANY_VALUE`](https://spark.apache.org/docs/4.1.0/api/sql/#any_value) | With limitations | The ignore-nulls argument, `any_value(col, true)`, is not supported. Which value a group returns can differ from Spark. |
| [`COLLECT_SET`](https://spark.apache.org/docs/4.1.0/api/sql/#collect_set) | With limitations | The order of the elements can differ from Spark. |
| [`FIRST_VALUE`](https://spark.apache.org/docs/4.1.0/api/sql/#first_value) | With limitations | Supported as a window function. The aggregate form, without `OVER`, is not. |
| [`GROUPING`](https://spark.apache.org/docs/4.1.0/api/sql/#grouping) | With limitations | Returns `INTEGER`, where Spark returns `TINYINT`. |
| [`LISTAGG`](https://spark.apache.org/docs/4.1.0/api/sql/#listagg) | With limitations | Without a delimiter, values are joined with `,`; Spark joins them with no separator. `listagg(DISTINCT col)` is not supported. |
| [`MEDIAN`](https://spark.apache.org/docs/4.1.0/api/sql/#median) | With limitations | Not supported for `INTERVAL` arguments. |
| [`PERCENTILE`](https://spark.apache.org/docs/4.1.0/api/sql/#percentile) | With limitations | An array of percentages is not supported, nor are `INTERVAL` arguments. |
| [`PERCENTILE_CONT`](https://spark.apache.org/docs/4.1.0/api/sql/#percentile_cont) | With limitations | Not supported for `INTERVAL` arguments. |
| [`PERCENTILE_DISC`](https://spark.apache.org/docs/4.1.0/api/sql/#percentile_disc) | With limitations | Returns `INTEGER`, where Spark returns `DOUBLE`. |
| [`STRING_AGG`](https://spark.apache.org/docs/4.1.0/api/sql/#string_agg) | With limitations | Names its result column `string_agg`, where Spark names it `listagg`. |
| [`SUM`](https://spark.apache.org/docs/4.1.0/api/sql/#sum) | With limitations | A column holding only untyped `NULL` literals raises an error, where Spark returns `NULL`. |
| `APPROX_PERCENTILE`, `APPROX_TOP_K`, `APPROX_TOP_K_ACCUMULATE`, `APPROX_TOP_K_COMBINE`, `BITMAP_AND_AGG`, `BITMAP_CONSTRUCT_AGG`, `BITMAP_OR_AGG`, `COUNT_MIN_SKETCH`, `FIRST`, `GROUPING_ID`, `HISTOGRAM_NUMERIC`, `HLL_SKETCH_AGG`, `HLL_UNION_AGG`, `KLL_SKETCH_AGG_BIGINT`, `KLL_SKETCH_AGG_DOUBLE`, `KLL_SKETCH_AGG_FLOAT`, `KURTOSIS`, `LAST`, `LAST_VALUE`, `MODE`, `PERCENTILE_APPROX`, `SKEWNESS`, `THETA_INTERSECTION_AGG`, `THETA_SKETCH_AGG`, `THETA_UNION_AGG`, `TRY_AVG`, `TRY_SUM` | Not supported | |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.