Window Functions, Visualised - Distribution
January 09, 2021
Let’s look at the window functions cume_dist
and ntile
, which I’ve dubbed “distribution functions”.
cume_dist
Shortform for cumulative distribution,
percentiles?
ntile
I liken ntile
to dividing your window frame equally into “buckets”:
An example:
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