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

问题描述

大多数数据库都具有用于计算中位数的内置函数,但在Amazon Redshift中我看不到中位数.

Most databases have a built in function for calculating the median but I don't see anything for median in Amazon Redshift.

您可以使用nth_value()和count()分析函数的组合来计算中位数,但这看起来有些古怪.如果分析数据库没有用于计算中位数的内置方法,我会感到非常惊讶,所以我假设我错过了一些东西.

You could calculate the median using a combination of the nth_value() and count() analytic functions but that seems janky. I would be very surprised if an analytics db didn't have a built in method for computing median so I'm assuming I'm missing something.

http://docs.aws.amazon.com/redshift/latest/dg/r_Examples_of_NTH_WF .html http://docs.aws.amazon.com/redshift/latest/dg/c_Window_functions.html

推荐答案

从2014年10月17日起,Redshift支持 MEDIAN 窗口函数:

And as of 2014-10-17, Redshift supports the MEDIAN window function:

# select min(median) from (select median(num) over () from temp);
 min
-----
 4.0

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

08-15 18:21