Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
I have a table with 8 set of numbers in a col, for which i need to calculate the median. and show the percentage.

Median Calculation::
3, 13, 7, 5, 21, 23, 23, 40

When we put those numbers in order we have::
3, 5, 7, 13, 21, 23, 23, 40
Taking the middle nums :: 13 and 21 .
To find the value halfway between them, add them together and divide by 2:
13 + 21 = 34
then 34 ÷ 2 = 17
So the Median in this example is 17.
So this is how we calc median , but i am unable to take the middle nums in sql. Please help me knowing how to take the middle nums 13 and 21 and also calculating the percentage of the median.

Please help.

Thanks in advance :)
Posted
Updated 23-Sep-15 22:54pm
v2
Comments
Herman<T>.Instance 24-Sep-15 4:26am    
You state under see more that the question is about sql server 2008 R2 or sql server 2012. For the 2012 version and newer a function is made for median calculations

2008: See HERE
2012: See HERE
pn46 24-Sep-15 4:55am    
My question is under sql server 2008 r2.
Herman<T>.Instance 24-Sep-15 4:57am    
Link is provided for :D
pn46 25-Sep-15 0:24am    
thanks for the response. It worked :)
Herman<T>.Instance 25-Sep-15 8:43am    
Superb!

1 solution

You state under see more that the question is about sql server 2008 R2 or sql server 2012. For the 2012 version and newer a function is made for median calculations

2008: See HERE
2012: See HERE
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900