NTILE

Distributes the rows in an ordered partition into a specified number of groups. The groups are numbered, starting at one. For each row, NTILE returns the number of the group to which the row belongs.

Syntax

NTILE (integer_expression) 
    OVER ( [ <partition_by_clause> ] < order_by_clause > )

Arguments

integer_expression

Is a positive integer constant expression that specifies the number of groups into which each partition must be divided. integer_expression can be of type int, or bigint.

Return types

float

Example

SELECT NTILE(5) OVER(PARTITION BY [IntColumn] ORDER BY [IntColumn]) AS [ntiled]
  FROM [IntTable]

See Also