PERCENTILE_DISC
functionsupportedCore SQL functionsReturns a percentile value based on a discrete distribution of the input column (specified in order_by_expr). The returned value is that whose row has the smallest CUME_DIST value that is greater than or equal to the given percentile. NULL values are ignored in the calculation.
Syntax
supportedpartialnot supportednot scored
Aggregate function
PERCENTILE_DISC( <percentile> ) WITHIN GROUP (ORDER BY <order_by_expr> )
Window function
PERCENTILE_DISC( <percentile> )
WITHIN GROUP (ORDER BY <order_by_expr> )
OVER ( [ PARTITION BY <expr3> ] )
Parameters
| Name | Required | Description |
|---|---|---|
percentile | required | The percentile of the value that you want to find. The percentile must be a constant between 0.0 and 1.0. For example, if you want to find the value at the 90th percentile, specify 0.9. |
order_by_expr | required | The expression (typically a column name) by which to order the values. For example, if you want to want to find the student whose math SAT score is at the 90th percentile, then specify the column containing the math SAT score. Note that this is also implicitly the column from which the returned value is chosen. For example, if you order by math SAT scores, then the result is one of the math SAT scores. You cannot order by one column and get a percentile value for a different column. |
expr3 | required | This is the optional expression used to group rows into partitions. |
Returns
Returns the value that is at the specified percentile.
Usage notes
- The percentile argument to the function must be a constant.
- DISTINCT is not supported for this function.
- The function PERCENTILE_CONT interpolates between the two closest values, while the function PERCENTILE_DISC chooses the closest value rather than interpolating.
- When this function is called as a window function, it does not support: An ORDER BY clause within the OVER clause.
- Explicit window frames.