NTILE
NTILE divides an ordered data set into a number of buckets indicated by expression and assigns the appropriate bucket number to each row.
Syntax
NTILE (expression1) OVER ( [ PARTITION BY expression [, ...] ]
ORDER BY expression [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] )
Remarks
• | The buckets are numbered 1 through expression1. |
• | The expression1 value must resolve to a positive constant for each partition. |
• | PARTITION BY is optional. |
• | ORDER BY is required. |
• | The window clause is not allowed. |