我正在尝试计算数据集(0和5)的五分位数范围,并将其用作我的计算基础(我从网站上粘贴了以下查询) http://www.sqlservercentral.com/articles/PERCENT_RANK/141532/
WITH C AS
(
SELECT
SalesPersonID,
SaleYear, SaleAmt,
rk = RANK() OVER (ORDER BY SaleAmt),
nr = COUNT(*) OVER ()
FROM ##Sales
)
SELECT
SalesPersonID,
SaleYear,
SaleAmt,
PercentileRank = 1.0*(rk-1)/(nr-1)
FROM C;
我需要修改什么才能使其达到五分之一范围?
答案 0 :(得分:0)
WITH C AS
(
SELECT
SalesPersonID,
SaleYear, SaleAmt,
rk = RANK() OVER (ORDER BY SaleAmt),
nr = COUNT(*) OVER ()
FROM ##Sales
)
SELECT
SalesPersonID,
SaleYear,
SaleAmt,
PercentileRank = 1.0*(rk-1)/(nr-1),
Quintile=(rk-1)/(nr/5)+1
FROM C;