我能夠使用以下查詢來獲得百分位數。我用一個單獨的計數/分鐘/最大/平均。
SELECT DISTINCT mj.title, PERCENTILE_DISC(.1) WITHIN GROUP (ORDER BY e.base)
OVER (PARTITION BY mj.title) AS '10th', PERCENTILE_DISC(.25) WITHIN GROUP (ORDER
BY e.base) OVER (PARTITION BY mj.title) AS '25th', PERCENTILE_DISC(.5) WITHIN
GROUP (ORDER BY e.base) OVER (PARTITION BY mj.title) AS '50th',
PERCENTILE_DISC(.75) WITHIN GROUP (ORDER BY e.base) OVER (PARTITION BY mj.title)
AS '75th', PERCENTILE_DISC(.9) WITHIN GROUP (ORDER BY e.base) OVER (PARTITION BY
mj.title) AS '90th' FROM dbo.ps_employee e FULL OUTER JOIN dbo.ps_jobs j on
e.title = j.job FULL OUTER JOIN dbo.ps_masterjobs mj
ON j.masterID = mj.ID;
PERCENTILE_DISC它不是聚合函數,如COUNT/MIN/MAX/AVG(列)。此異常由此功能使用的列生成,但不用於分組:e.base。最簡單的解決方案可能是創建一個單獨的查詢來計算百分位數。 –
確實刪除(ORDER BY e.base)更改業務邏輯? –
不,我認爲ORDER BY是PERCENTILE_DISC函數所要求的嗎? – gattoun