2017-03-16 206 views
-1

我正在寻找一种方法来计算一组数值的中位数。 我已经尝试了很多方法来做到这一点,但我的SQL版本(9.6.1 Linux)不允许我这样做(特别是,选择最高的50%)。PSQL中位数或四分位数

有什么建议吗?

回答

0

9.6.1是Postgres服务器或客户端版本,不是SQL。 请检查出some docs。下面是一个例子:

t=# with t as (select generate_series(1,200,1) s) select percentile_cont(0.5) within group (order by s), percentile_cont(0.25) within group (order by s) from t; 
percentile_cont | percentile_cont 
-----------------+----------------- 
      100.5 |   50.75 
(1 row) 

Time: 0.378 ms