Description

The PERCENTILE_APPROX function is used to calculate approximate percentiles. It returns the approximate percentile of the specified column values in a table.

Syntax

PERCENTILE_APPROX(value_expr, percentile)

Parameter Description

  • value_expr: The numerical expression for which the percentile is to be calculated.
  • percentile: The desired percentile (between 0 and 1).
  • column: The column used to calculate the percentile, usually sorted by this column.

Return Result

Returns the approximate value of the specified percentile.

Example

SELECT percentile_approx(col, array(0.5, 0.4, 0.1)) as res
    FROM VALUES (0), (1), (2), (10) AS tab(col);
+---------------+
|      res      |
+---------------+
| [1.0,1.1,0.0] |
+---------------+