percentile_cont
彙總函式
適用于: Databricks SQL Databricks Runtime 10.3 和更新版本
傳回值,這個值會使用連續分佈模型對應至 percentile
提供的 sortKey
。
語法
percentile_cont ( percentile )
WITHIN GROUP (ORDER BY sortKey [ASC | DESC] )
您也可以使用 OVER
子句,將此函式叫用為視窗函式。
參數
percentile
:介於 0 到 1 之間的數值常值或數值常值陣列,每個常值介於 0 到 1 之間。sortKey
:將計算百分位數的數值運算式。ASC
或DESC
:選擇性地指定是否使用遞增或遞減順序來計算百分位數。 預設值為ASC
。
返回
如果 percentile
是數值,則為 DOUBLE,如果 percentile
為 ARRAY,則為 DOUBLE 的 ARRAY。
彙總函式會傳回 群組內的 sortKey
插補百分位數。
例子
-- Return the median, 40%-ile and 10%-ile.
> SELECT percentile_cont(array(0.5, 0.4, 0.1)) WITHIN GROUP (ORDER BY col)
FROM VALUES (0), (1), (2), (10) AS tab(col);
[1.5, 1.2000000000000002, 0.30000000000000004]
-- Return the interpolated median.
> SELECT percentile_cont(0.50) WITHIN GROUP (ORDER BY col)
FROM VALUES (0), (6), (6), (7), (9), (10) AS tab(col);
6.5