Skip to main content

NTILE (SQL)

A window function that splits the row within the specified window frame into num-groups number of groups that each have a roughly equal number of elements.

Synopsis

NTILE(num-groups)

Description

NTILE splits up the rows in the window frame into num-groups groups such that each group contains about the same number of elements. Each group is identified by a number, starting from one.

Arguments

num-groups

A number that specifies how many groups to split the rows into.

Examples

The following example splits up employees within each department into four groups based on their salaries:

SELECT NTILE(4) OVER (PARTITION BY Department ORDER BY Salary) FROM Company.Employee

See Also

FeedbackOpens in a new tab