如何计算Sql Server中偶数Nums的中位数 [英] How Do I Calculate Median For Even Set Of Nums In Sql Server

查看:110
本文介绍了如何计算Sql Server中偶数Nums的中位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在一个col中有一组包含8组数字的表,我需要计算中位数。并显示百分比。



中位数计算::

3,13,7,5,21,23,23,40



当我们按顺序排列这些数字时,我们有::

3,5,7,13,21,23,23,40

取中间的数字:: 13和21.

要找到它们之间的值,将它们加在一起并除以2:

13 + 21 = 34

然后34÷2 = 17

所以这个例子中的中位数是17.

所以这就是我们计算中位数的方法,但我无法在sql中采取中间的nums。请帮助我知道如何取中间数13和21以及计算中位数的百分比。



请帮忙。



在此先感谢:)


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 :)

推荐答案

你在下面看到更多的问题是关于sql server 2008 R2或sql server 2012的问题。对于2012年版本和更新的功能用于中位数计算



2008:参见 HERE

2012:见 HERE
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


这篇关于如何计算Sql Server中偶数Nums的中位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆