NTILE
Splits rows into the given number of groups of roughly equal size and numbers the groups.
Syntax
NTILE(<group count>) OVER (ORDER BY <sort key>)
NTILE(<group count>) OVER (PARTITION BY <group> ORDER BY <sort key>)
Deals ordered rows into N groups and tells you which group each row is in: 1, 2, …, N. If the rows don't divide evenly, the extra ones go to the first groups. That's how you split into halves, thirds or quarters: “the more expensive half of orders”, “the top 25% by salary”.