当前位置:Gxlcms >
数据库问题 >
SQL Server ->> PERCENTILE_CONT、PERCENTILE_DISC 和 PERCENT_RANK 函数
SQL Server ->> PERCENTILE_CONT、PERCENTILE_DISC 和 PERCENT_RANK 函数
时间:2021-07-01 10:21:17
帮助过:1人阅读
AdventureWorks2012;
SELECT DISTINCT Name
AS DepartmentName
,PERCENTILE_CONT(0.5) WITHIN
GROUP (
ORDER BY ph.Rate)
OVER (PARTITION
BY Name)
AS MedianCont
,PERCENTILE_DISC(0.5) WITHIN
GROUP (
ORDER BY ph.Rate)
OVER (PARTITION
BY Name)
AS MedianDisc
FROM HumanResources.Department
AS d
INNER JOIN HumanResources.EmployeeDepartmentHistory
AS dh
ON dh.DepartmentID
= d.DepartmentID
INNER JOIN HumanResources.EmployeePayHistory
AS ph
ON ph.BusinessEntityID
= dh.BusinessEntityID
WHERE dh.EndDate
IS NULL;
PERCENT_RANK虽然也带有PERCENT,但是和前两个没有什么关系。它是为了计算当前值按百分比计算所处在百分位位置。
参考:
PERCENTILE_CONT (Transact-SQL)
PERCENTILE_DISC (Transact-SQL)
PERCENT_RANK (Transact-SQL)
SQL Server ->> PERCENTILE_CONT、PERCENTILE_DISC 和 PERCENT_RANK 函数
标签: