大多数数据库都有一个用于计算中位数的内置函数,但我在Amazon Redshift中看不到任何中位数.
您可以使用nth_value()和count()分析函数的组合来计算中值,但这看起来很笨拙.如果分析数据库没有内置计算中位数的方法,我会非常惊讶所以我假设我错过了一些东西.
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窗口功能:
# select min(median) from (select median(num) over () from temp); min ----- 4.0