QUANTILE
Description
This function calculates the given quantile value per group. QUANTILE can be applied to INT, FLOAT or DATE columns.
The quantile parameter passed to this function has to be an expression that results in a constant float number between 0 (same as MIN) and 1.0 (same as MAX).
To calculate a quantile value for a group, we first sort all values of this group and calculate the index at which the quantile value is located. The value at this index is then returned. If the calculated index is a decimal number (e.g., 1.5), it is rounded up. For example, suppose you want to calculate the 0.25 quantile for the following group: [ 1 , 3 , 3 , 4 , 4 , 5 ]. The calculated index in this case is 1.5, which means that the final quantile value cannot be clearly determined. We therefore round the calculated index up to 2 and return 3 as the final quantile value for this group.
Warning
This operator supports both exact and approximate calculations. By default, calculations are exact to ensure precision and compliance with the SOC 1 (Service Organization Control) standard. However, we recommend using approximate calculations whenever possible, as they provide significant performance gains with minimal impact on accuracy. To enable this mode, use the APPROX keyword.
Syntax
QUANTILE ( [APPROX|EXACT] table.column, quantile )
NULL handling
NULL values are ignored, so they do not influence the result. If all the values of a group are NULL, the result for this group is also NULL. The quantile parameter is not allowed to be NULL.
Examples
[1] Get 0 quantile of column. | ||||||||||
| ||||||||||
|
[2] Get 1.0 quantile of column. | ||||||||||
| ||||||||||
|
[3] Get the min quantile by country. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
|
[4] Get the 0.5 quantile mixed with nulls, grouped by country. | ||||||||||||||||||
| ||||||||||||||||||
|
[5] Get the 0.5 quantile using a division as the quantile parameter. | |||||||||||||
| |||||||||||||
|