PERCENTILE DISC 和 PERCENTILE CONT
PERCENTILE_DISC
函式列出第一個條目的值,其中累積分佈高於你使用 numeric_literal
引數提供的百分位數。
這些值按行集或分割槽分組,由 WITHIN GROUP
子句指定。
PERCENTILE_CONT
函式類似於 PERCENTILE_DISC
函式,但返回第一個匹配條目和下一個條目之和的平均值。
SELECT BusinessEntityID, JobTitle, SickLeaveHours,
CUME_DIST() OVER(PARTITION BY JobTitle ORDER BY SickLeaveHours ASC)
AS "Cumulative Distribution",
PERCENTILE_DISC(0.5) WITHIN GROUP(ORDER BY SickLeaveHours)
OVER(PARTITION BY JobTitle) AS "Percentile Discreet"
FROM Employee;
要從匹配或超過 0.5 百分位數的行中找到確切的值,請將百分位數作為 PERCENTILE_DISC
函式中的數字文字傳遞。結果集中的 Percentile Discreet 列列出了累積分佈高於指定百分位數的行的值。
BusinessEntityID |
職稱 | SickLeaveHours | 累積分佈 | 百分位謹慎 |
---|---|---|---|---|
272 |
應用專家 | 55 | 0.25 | 56 |
268 |
應用專家 | 56 | 0.75 | 56 |
269 |
應用專家 | 56 | 0.75 | 56 |
267 |
應用專家 | 57 | 1 | 56 |
要將計算基於一組值,請使用 PERCENTILE_CONT
函式。結果中的 Percentile Continuous
列列出了結果值和下一個最高匹配值之和的平均值。
SELECT BusinessEntityID, JobTitle, SickLeaveHours,
CUME_DIST() OVER(PARTITION BY JobTitle ORDER BY SickLeaveHours ASC)
AS "Cumulative Distribution",
PERCENTILE_DISC(0.5) WITHIN GROUP(ORDER BY SickLeaveHours)
OVER(PARTITION BY JobTitle) AS "Percentile Discreet",
PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY SickLeaveHours)
OVER(PARTITION BY JobTitle) AS "Percentile Continuous"
FROM Employee;
BusinessEntityID |
職稱 | SickLeaveHours | 累積分佈 | 百分位謹慎 | 百分位連續 |
---|---|---|---|---|---|
272 |
應用專家 | 55 | 0.25 | 56 | 56 |
268 |
應用專家 | 56 | 0.75 | 56 | 56 |
269 |
應用專家 | 56 | 0.75 | 56 | 56 |
267 |
應用專家 | 57 | 1 | 56 | 56 |