APPROX_PERCENTILE
functionsupportedCore SQL functionsReturns an approximated value for the desired percentile (that is, if column c has n numbers, APPROX_PERCENTILE(c, p) returns a number such that approximately n * p of the numbers in c are smaller than the returned number). This function uses an improved version of the t-Digest algorithm. For more information, see Estimating Percentile Values.
Syntax
supportedpartialnot supportednot scored
Aggregate function
APPROX_PERCENTILE( <expr> , <percentile> )
Window function
APPROX_PERCENTILE( <expr> , <percentile> ) OVER ( [ PARTITION BY <expr3> ] )
Parameters
| Name | Required | Description |
|---|---|---|
expr | required | A valid expression, such as a column name, that evaluates to a numeric value. |
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…). For example, the value 0.65 indicates the 65th percentile. |
expr3 | required | This is the optional expression used to group rows into partitions. |
Returns
The output is returned as a DOUBLE value.
Usage notes
- Percentile works only on numeric values, so expr should produce values that are numbers or can be cast to numbers.
- The values returned are not necessarily in the data set.
- The value returned is an approximation. The size of the data set and the skew in the data set affect the accuracy of the approximation.
- When this function is called as a window function, it does not support: An ORDER BY clause within the OVER clause.
- Explicit window frames.
- Decimal-float (DECFLOAT) values aren’t supported.