3

I just read the documentation and in specific this page, but I can not figure out one example (for example use case of this functions in analytics) in which I will use this, please could you help me with this mind-stopper?

Jon7
  • 7,165
  • 2
  • 33
  • 39
nanounanue
  • 7,942
  • 7
  • 41
  • 73

1 Answers1

8

If the examples in Michael Paquier's 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;

With detailed explanation:

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. [...]

There is more, read the manual.

Still not enough? Depesz also posted a detailed blog post.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • The last link has some good examples. Thank you. (The documentation and the other link I posted, had examples but didn't show a use case as the link you suggested ). – nanounanue Mar 25 '15 at 13:19