Improved StackOverflow Rank and Percentile

0

Please login or register to vote for this query.

(click on this box to dismiss)

Biology

Q&A for biology researchers, academics, and students

-- Improved StackOverflow Rank and Percentile
-- Original by Cade Roux
-- Revised to prevent "Arithmetic overflow error converting bigint to data type numeric."

WITH Rankings AS (
SELECT Id, Ranking = ROW_NUMBER() OVER(ORDER BY Reputation DESC)
FROM Users
)
,Counts AS (
SELECT Cnt = COUNT(*)
FROM Users
)
SELECT Id, Ranking, Cnt AS Total_Users, 100 - ((CAST(Ranking AS decimal(6))/Cnt) * 100) AS Percentile
FROM Rankings, Counts
WHERE Id = ##UserId##

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results