APPROX_PERCENTILE_ESTIMATE

functionsupportedCore SQL functions

docs.snowflake.com ↗

Aggregate functionsWindow function syntax and usage

Returns 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

NameRequiredDescription
staterequiredAn expression that contains state information generated by a call to APPROX_PERCENTILE_ACCUMULATE or APPROX_PERCENTILE_COMBINE.
percentilerequiredA 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

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.

See also

Referenced by