This function is used to approximate the pth percentile (including floating-point numbers) of a numeric column within a group.
percentile_approx(DOUBLE col, p [, B])
Parameter |
Mandatory |
Description |
|---|---|---|
col |
Yes |
Columns with a data type of numeric. If the values are of any other type, NULL is returned. |
p |
Yes |
The value should be between 0 and 1. Otherwise, NULL is returned. |
B |
Yes |
The parameter B controls the accuracy of the approximation, with a higher value of B resulting in a higher level of approximation. The default value is 10000. If the number of non-repeating values in the column is less than B, an exact percentile is returned. |
The return value is of the DOUBLE type.
select PERCENTILE_APPROX(items,0.5,100) from warehouse;
The command output is as follows:
+------------+ | _c0 | +------------+ | 521 | +------------+
select warehouseId, PERCENTILE_APPROX(items, 0.5, 100) from warehouse group by warehouseId;
The command output is as follows:
+------------+------------+ | warehouseId| _c1 | +------------+------------+ | city1 | 499 | | city2 | 354 | | city3 | 565 | +------------+------------+