Script to calculate the Median value for SQL Server data

  • Article

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.


2,817 reads

Pivoting, Unpivoting and Aggregating

  • Article

We asked Phil Factor to write a nice simple quick-start guide about aggregation, pivoting and un-pivoting techniques. To do so, he takes us all the way from getting the data from a published source, transferring it to SQL Server, un-pivoting it, storing it in a relational table, aggregating it and finally pivoting the data in a variety of ways.


4,484 reads


Updated Pluralsight Course – Managing the Kubernetes API Server and Pods


My updated course “Managing the Kubernetes API Server and Pods” in now available on Pluralsight here! If...

Daily Coping 11 May 2021


I started to add a daily coping tip to the SQLServerCentral newsletter and to...

What do you do when technology changes? : T-SQL Tuesday #138


Our host for this month’s TSQL Tuesday is Andy Leonard (blog|twitter). He’d like us...

Read the latest Blogs


SQL Server 2019 container kubernetes

By andreas.kreuzberg

Hi everyone, can anyone tell me, if the sql server 2019 is ready for...

Potential set based solution

By kangarolf

Hi all, I'm a total novice when it comes to thinking about set based...

Copy value from one row to another if column matches

By bent

Hi there, I just don't get it. Need to update rows in same table....

Visit the forum


SQL Server Q&A from the SQLServerCentral community

Get answers