What\'s the best way to calculate percentile rankings (e.g. the 90th percentile or the median score) in MSSQL 2005?
I\'d like to be able to select the 25th, median,
Percentile is calculated by
(Rank -1) /(total_rows -1)
when you sort values in ascending order.
The below query will give you percentile value between 0 and 1. Person with lowest marks will have 0 percentile.
SELECT Name, marks, (rank_1-1)/((select count(*) as total_1 from table)-1)as percentile_rank
from
(
SELECT Name,
Marks,
RANK() OVER (ORDER BY Marks) AS rank_1
from table
) as A