PostgreSQL equivalent of Oracle's PERCENTILE_CONT function

前端 未结 2 876
清酒与你
清酒与你 2021-02-06 03:15

Has anyone found a PostgreSQL equivalent of Oracle\'s PERCENTILE_CONT function? I searched, and could not find one, so I wrote my own.

Here is the solution that I hope

2条回答
  •  囚心锁ツ
    2021-02-06 04:05

    With PostgreSQL 9.4 there is native support for percentiles now, implemented in Ordered-Set Aggregate Functions:

    percentile_cont(fraction) WITHIN GROUP (ORDER BY sort_expression) 
    

    continuous percentile: returns a value corresponding to the specified fraction in the ordering, interpolating between adjacent input items if needed

    percentile_cont(fractions) WITHIN GROUP (ORDER BY sort_expression)
    

    multiple continuous percentile: returns an array of results matching the shape of the fractions parameter, with each non-null element replaced by the value corresponding to that percentile

    See the documentation for more details: http://www.postgresql.org/docs/current/static/functions-aggregate.html

提交回复
热议问题