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

> Computes multiple approximate quantiles using the t-digest algorithm at different levels simultaneously, taking into account the weight of each element.

# quantilesTDigestWeighted

<h2 id="quantilesTDigestWeighted">
  quantilesTDigestWeighted
</h2>

Introduced in: v20.1.0

Computes multiple approximate [quantiles](https://en.wikipedia.org/wiki/Quantile) of a numeric data sequence at different levels simultaneously using the [t-digest](https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf) algorithm.
The function takes into account the weight of each sequence member.

This function is equivalent to [`quantileTDigestWeighted`](/reference/functions/aggregate-functions/quantileTDigestWeighted) but allows computing multiple quantile levels in a single pass, which is more efficient than calling individual quantile functions.

The maximum error is 1%. Memory consumption is `log(n)`, where `n` is a number of values.

The performance of the function is lower than performance of [`quantiles`](/reference/functions/aggregate-functions/quantiles) or [`quantilesTiming`](/reference/functions/aggregate-functions/quantilesTiming).
In terms of the ratio of State size to precision, this function is much better than `quantiles`.

The result depends on the order of running the query, and is nondeterministic.

<Note>
  Using `quantilesTDigestWeighted` [is not recommended for tiny data sets](https://github.com/tdunning/t-digest/issues/167#issuecomment-828650275) and can lead to significant error.
  In this case, consider possibility of using [`quantilesTDigest`](/reference/functions/aggregate-functions/quantilesTDigest) instead.
</Note>

**Syntax**

```sql theme={null}
quantilesTDigestWeighted(level1, level2, ...)(expr, weight)
```

**Parameters**

* `level` — Levels of quantiles. One or more constant floating-point numbers from 0 to 1. We recommend using `level` values in the range of `[0.01, 0.99]`. [`Float*`](/reference/data-types/float)

**Arguments**

* `expr` — Expression over the column values resulting in numeric data types, `Date` or `DateTime`. [`(U)Int*`](/reference/data-types/int-uint) or [`Float*`](/reference/data-types/float) or [`Date`](/reference/data-types/date) or [`DateTime`](/reference/data-types/datetime)
* `weight` — Column with weights of sequence elements. Weight is a number of value occurrences. [`UInt*`](/reference/data-types/int-uint)

**Returned value**

Array of approximate quantiles of the specified levels in the same order as the levels were specified. For `Date` and `DateTime` inputs the output format matches the input format. [`Array(Float32)`](/reference/data-types/array) or [`Array(Date)`](/reference/data-types/array) or [`Array(DateTime)`](/reference/data-types/array)

**Examples**

**Computing multiple weighted quantiles with t-digest**

```sql title=Query theme={null}
SELECT quantilesTDigestWeighted(0.25, 0.5, 0.75)(number, 1) FROM numbers(100);
```

```response title=Response theme={null}
┌─quantilesTDigestWeighted(0.25, 0.5, 0.75)(number, 1)──┐
│ [24.75,49.5,74.25]                                    │
└───────────────────────────────────────────────────────┘
```
