Examples of ordered set aggregates in Postgres
✓ Published0🌍 Public
CCaged
Last edited Apr 5, 2016
Created on Apr 5, 2016
This example shows how Postgres’s ordered set aggregates compute distribution percentiles for a player statistic, both globally and per season, with rounded averages alongside. The first query returns a single row with the overall average and an array of percentiles (25th, 50th, 75th, 95th), while the second groups the same computation by season, revealing how the distribution shifts slightly over time. It uses the `percentile_cont` function with a `WITHIN GROUP (ORDER BY ...)` clause, which is a native SQL aggregate, not a visualization library. The code also relies on the `round` and `avg` functions, and the output is plain tabular text, with no graphical rendering involved.
AI-generated description