APPROX_PERCENTILE_ESTIMATE
functionsupportedCore SQL functionsReturns the desired approximated percentile value for the specified t-Digest state. A t-Digest state produced by APPROX_PERCENTILE_ACCUMULATE and APPROX_PERCENTILE_COMBINE can be used to compute a percentile estimate using this function. As such, APPROX_PERCENTILE_ESTIMATE(APPROX_PERCENTILE_ACCUMULATE(…)) is equivalent to APPROX_PERCENTILE(…).
Syntax
APPROX_PERCENTILE_ESTIMATE( <state> , <percentile> )
Parameters
| Name | Required | Description |
|---|---|---|
state | required | An expression that contains state information generated by a call to APPROX_PERCENTILE_ACCUMULATE or APPROX_PERCENTILE_COMBINE. |
percentile | required | A constant real value greater than or equal to 0.0 and less than 1.0. This indicates the percentile from 0 to 99.999… (e.g. the value 0.65 indicates the 65th percentile). |
Usage notes
- Decimal-float (DECFLOAT) values aren’t supported.
Example
Consider a scenario where you need to approximate multiple percentile values from a given set of numbers. This can be done by creating the state and then using APPROX_PERCENTILE_ESTIMATE to calculate all the percentiles: - First, store the state: Copy code CREATE OR REPLACE TABLE resultstate AS ( SELECT APPROX_PERCENTILE_ACCUMULATE(c1) AS s FROM testtable ); - Then, query the state for multiple percentiles: Copy code SELECT APPROX_PERCENTILE_ESTIMATE(s, 0.01), APPROX_PERCENTILE_ESTIMATE(s, 0.15), APPROX_PERCENTILE_ESTIMATE(s, 0.845) FROM testtable; For a more extensive example, see the Examples section in APPROX_PERCENTILE_ACCUMULATE.