NTILE Window Function
The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.
NTILE (expr) OVER ( [ PARTITION BY expression_list ] [ ORDER BY order_list ] )
The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expr argument must not be nullable.
A clause that specifies the window partitioning and ordering. The OVER clause cannot contain a window frame specification.
- PARTITION BY window_partition
Optional. The range of records for each group in the OVER clause.
- ORDER BY window_ordering
Optional. An expression that sorts the rows within each partition. If the ORDER BY clause is omitted, the ranking behavior is the same.
If ORDER BY does not produce a unique ordering, the order of the rows is nondeterministic. For more information, see Unique Ordering of Data for Window Functions.