Is there a better way to calculate the median (not average)

前端 未结 7 828
我在风中等你
我在风中等你 2021-02-02 15:38

Suppose I have the following table definition:

CREATE TABLE x (i serial primary key, value integer not null);

I want to calculate the MEDIAN o

7条回答
  •  被撕碎了的回忆
    2021-02-02 16:12

    Indeed there IS an easier way. In Postgres you can define your own aggregate functions. I posted functions to do median as well as mode and range to the PostgreSQL snippets library a while back.

    http://wiki.postgresql.org/wiki/Aggregate_Median

提交回复
热议问题