NTILE
ranking
What changes
- Input
- partition and ORDER BY columns of OVER
- Output or change
- one rank or number per row
- Return type
- bigint
Syntax at a glance
NTILE (integer_expression) OVER ( [ <partition_by_clause> ] <order_by_clause> )
Work example
Split ordered rows into a requested number of near-equal buckets.
Try a row count that does not divide evenly and inspect which buckets receive extra rows.
Check your work NTILE needs a deterministic order when bucket membership matters.
Practice SQL
Open in SQL FlowSELECT n, NTILE(2) OVER (ORDER BY n) AS bucket FROM (VALUES (1), (2), (3), (4), (5)) AS v(n);
Open Microsoft Learn for full syntax, permissions, and details for your version.