Description
The PERCENTILE_APPROX function calculates the approximate percentile of a numeric column. Compared to the exact PERCENTILE function, PERCENTILE_APPROX offers better performance on large datasets and is suitable for scenarios where high precision is not required.
Syntax
Parameters
- value_expr: The numeric column or expression for which to calculate the percentile. Supports numeric types.
- percentile: The desired percentile, either a
DOUBLEconstant in the range 0 to 1, or an array of percentiles (ARRAY<DOUBLE>). When an array is passed, the function returns multiple percentile results at once.
Return Results
- When a single percentile is passed, returns a
DOUBLEapproximation. - When an array is passed, returns an
ARRAY<DOUBLE>, where each element corresponds to the percentile at the same position in the input array. NULLvalues are excluded from the calculation.
Examples
- Calculate a single percentile (50th percentile, i.e., median):
- Calculate multiple percentiles at once:
- Calculate the median by group:
- Calculate the 25th and 75th percentiles (quartiles):
