StackOverflow Rank and Percentile

0

Please login or register to vote for this query.

(click on this box to dismiss)

Lifehacks

Q&A for people looking to bypass life's everyday problems with simple tricks

-- StackOverflow Rank and Percentile

WITH Rankings AS (
SELECT Id, Ranking = ROW_NUMBER() OVER(ORDER BY Reputation DESC)
FROM Users
)
,Counts AS (
SELECT Count = COUNT(*), SUM(CASE When Id = ##UserId## THEN Reputation Else 0 END) As Reputation
FROM Users
WHERE Reputation > 100
AND LOWER(Location) LIKE '%canada%'
)
SELECT
      Id,
      (SELECT Reputation FROM Counts) AS Reputation,
      Ranking,
      (SELECT Count FROM Counts) AS TotalUsers,
      (1-CAST(Ranking AS decimal(10, 5)) / (SELECT Count FROM Counts))*100 AS Percentile
FROM Rankings
WHERE Id = ##UserId##

Enter Parameters

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