Let’s look at the window functions
ntile, which I’ve dubbed “distribution functions”.
Shortform for cumulative distribution,
ntile to dividing your window frame equally into “buckets”:
SELECT ntile(3) OVER(ORDER BY cost DESC), ... FROM expenses;
In the above, we’re asking Postgres to divide the frame into 3 buckets:
Following from window functions for rankings