According to MSDN, Median is not available as an aggregate function in Transact-SQL. However, I would like to find out whether it is possible to create this functionality (using the Create Aggregate function, user defined function, or some other method).
What would be the best way (if possible) to do this – allow for the calculation of a median value (assuming a numeric data type) in an aggregate query?
Best Answer
If you're using SQL 2005 or better this is a nice, simple-ish median calculation for a single column in a table: