Median reputation

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Apps

Q&A for apps, scripts, and development with the Stack Exchange API

---way to calculate median suggested by Jeff Attwood
---https://stackoverflow.com/questions/1342898/function-to-calculate-median-in-sql-server/2026609#2026609

DECLARE @minRep int = '##min?101##'

SELECT
(
 (SELECT MAX(Reputation) FROM
   (SELECT TOP 50 PERCENT Reputation FROM Users WHERE Reputation>=##min## ORDER BY Reputation) AS BottomHalf)
 +
 (SELECT MIN(Reputation) FROM
   (SELECT TOP 50 PERCENT Reputation FROM Users WHERE Reputation>=##min## ORDER BY Reputation DESC) AS TopHalf)
) / 2 AS Median

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results