2017-03-16 134 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