Joe Celko explains how NTILE() works:
The SQL
NTILE()
is a window function that allows you to break a table into a specified number of approximately equal groups, or<bucket count>
. For each row in a grouping, theNTILE()
function assigns a bucket number representing the group to which the row belong starting at one.
Click through for the explanation, including what it is and isn’t, as well as several examples.