有人可以举例说明 PostgreSQL 9.4 中有序集函数的用例吗?
Can someone give examples of use case of the ordered-set functions in PostgreSQL 9.4?
我刚刚阅读了文档,特别是这个page,但我想不出一个例子(例如这个函数在分析中的用例)我将在其中使用它,请你帮忙我用这个脑塞?
如果Michael Paquier blog post you are referring to are not enough, there is another one in the manual中的例子:
SELECT percentile_disc(0.5) WITHIN GROUP (ORDER BY income) FROM households;
详细解释:
There is a subclass of aggregate functions called ordered-set
aggregates for which an order_by_clause is required, usually because
the aggregate's computation is only sensible in terms of a specific
ordering of its input rows. Typical examples of ordered-set aggregates
include rank and percentile calculations. For an ordered-set
aggregate, the order_by_clause is written inside WITHIN GROUP (...)
,
as shown in the final syntax alternative above. [...]
还有很多,不用一一列举了。阅读手册。
我刚刚阅读了文档,特别是这个page,但我想不出一个例子(例如这个函数在分析中的用例)我将在其中使用它,请你帮忙我用这个脑塞?
如果Michael Paquier blog post you are referring to are not enough, there is another one in the manual中的例子:
SELECT percentile_disc(0.5) WITHIN GROUP (ORDER BY income) FROM households;
详细解释:
There is a subclass of aggregate functions called ordered-set aggregates for which an order_by_clause is required, usually because the aggregate's computation is only sensible in terms of a specific ordering of its input rows. Typical examples of ordered-set aggregates include rank and percentile calculations. For an ordered-set aggregate, the order_by_clause is written inside
WITHIN GROUP (...)
, as shown in the final syntax alternative above. [...]
还有很多,不用一一列举了。阅读手册。