SQL Flow Field Guide

NTILE

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

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 Flow
SELECT 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.