> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8c05c8a2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Documentation for the SimpleAggregateFunction data type

# SimpleAggregateFunction Type

<h2 id="description">
  Description
</h2>

The `SimpleAggregateFunction` data type stores the intermediate state of an
aggregate function, but not its full state as the [`AggregateFunction`](/reference/data-types/aggregatefunction)
type does.

This optimization can be applied to functions for which the following property
holds:

> the result of applying a function `f` to a row set `S1 UNION ALL S2` can
> be obtained by applying `f` to parts of the row set separately, and then again
> applying `f` to the results: `f(S1 UNION ALL S2) = f(f(S1) UNION ALL f(S2))`.

This property guarantees that partial aggregation results are enough to compute
the combined one, so we do not have to store and process any extra data. For
example, the result of the `min` or `max` functions require no extra steps to
calculate the final result from the intermediate steps, whereas the `avg` function
requires keeping track of a sum and a count, which will be divided to get the
average in a final `Merge` step which combines the intermediate states.

Aggregate function values are commonly produced by calling an aggregate function
with the [`-SimpleState`](/reference/functions/aggregate-functions/combinators#-simplestate) combinator appended to the function name.

<h2 id="syntax">
  Syntax
</h2>

```sql theme={null}
SimpleAggregateFunction(aggregate_function_name, types_of_arguments...)
```

**Parameters**

* `aggregate_function_name` - The name of an aggregate function.
* `Type` - Types of the aggregate function arguments.

<h2 id="supported-functions">
  Supported functions
</h2>

The following aggregate functions are supported:

* [`any`](/reference/functions/aggregate-functions/any)
* [`any_respect_nulls`](/reference/functions/aggregate-functions/any)
* [`anyLast`](/reference/functions/aggregate-functions/anyLast)
* [`anyLast_respect_nulls`](/reference/functions/aggregate-functions/anyLast)
* [`min`](/reference/functions/aggregate-functions/min)
* [`max`](/reference/functions/aggregate-functions/max)
* [`sum`](/reference/functions/aggregate-functions/sum)
* [`sumWithOverflow`](/reference/functions/aggregate-functions/sumWithOverflow)
* [`groupBitAnd`](/reference/functions/aggregate-functions/groupBitAnd)
* [`groupBitOr`](/reference/functions/aggregate-functions/groupBitOr)
* [`groupBitXor`](/reference/functions/aggregate-functions/groupBitXor)
* [`groupArrayArray`](/reference/functions/aggregate-functions/groupArrayArray)
* [`groupUniqArrayArray`](/reference/functions/aggregate-functions/groupUniqArray)
* [`groupUniqArrayArrayMap`](/reference/functions/aggregate-functions/combinators#-map)
* [`sumMap` (`sumMappedArrays`)](/reference/functions/aggregate-functions/sumMap)
* [`minMap` (`minMappedArrays`)](/reference/functions/aggregate-functions/minMap)
* [`maxMap` (`maxMappedArrays`)](/reference/functions/aggregate-functions/maxMap)

<Note>
  Values of the `SimpleAggregateFunction(func, Type)` have the same `Type`,
  so unlike with the `AggregateFunction` type there is no need to apply
  `-Merge`/`-State` combinators.

  The `SimpleAggregateFunction` type has better performance than the `AggregateFunction`
  for the same aggregate functions.
</Note>

<h2 id="example">
  Example
</h2>

```sql theme={null}
CREATE TABLE simple (id UInt64, val SimpleAggregateFunction(sum, Double)) ENGINE=AggregatingMergeTree ORDER BY id;
```

<h2 id="related-content">
  Related Content
</h2>

* Blog: [Using Aggregate Combinators in ClickHouse](https://clickhouse.com/blog/aggregate-functions-combinators-in-clickhouse-for-arrays-maps-and-states)    - Blog: [Using Aggregate Combinators in ClickHouse](https://clickhouse.com/blog/aggregate-functions-combinators-in-clickhouse-for-arrays-maps-and-states)
* [AggregateFunction](/reference/data-types/aggregatefunction) type.
