Script to calculate the Median value for SQL Server data

Posted on SQL Server Central See other posts from SQL Server Central
Published on Tue, 08 Nov 2011 07:00:00 UT Indexed on 2011/11/11 18:13 UTC
Read the original article Hit count: 312

Filed under:

The standard SQL language has a number of aggregate functions like: SUM, MIN, MAX, AVG, but a common statistics function that SQL Server does not have is a built-in aggregate function for median. The median is the value that falls in the middle of a sorted resultset with equal parts that are smaller and equal parts that are greater. Since there is no built-in implementation for the median, the following is a simple solution I put together to find the median.

SQL Backup Pro Get smart with SQL Backup Pro
Powerful centralised management, encryption and more.
SQL Backup Pro was the smartest kid at school.
Discover why.

© SQL Server Central or respective owner