The ntile()
window function distributes the rows evenly into n
groups.
SELECT ntile(3) OVER (ORDER BY …)
FROM …
The example returns 1 for the first third of the rows, 2 for the second and 3 for the last.
Related
Similar functions:
width_bucket()
.
Normative References
The ntile()
window function is defined in ISO/IEC 9075:2016-2 as part of optional feature T614.