Syntax
Parameters
| Parameter | Description | Supported input types |
|---|---|---|
<value> | An integer expression used for the NTILE() function to specify the number of buckets for division. | INTEGER/BIGINT |
<partition_by> | An expression used for the partition by clause. | Any |
<order_by> | An expression used for the order by clause. | Any |
Return Type
INTEGER/BIGINT
If there is a remainder after dividing the rows in a partition by the argument value, it will result in buckets of different sizes. For example,
NTILE(2)over 5 rows will result in 2 buckets, the first with 3 rows, the second with 2NTILE(3)over 5 rows results in 3 buckets, the first 2 with 2 rows each and the last with one.
Example
The example below divides students test results into three buckets depending on their score.| student_name | score | bucket |
|---|---|---|
| James | 9 | 1 |
| Emma | 10 | 1 |
| Harry | 11 | 1 |
| Liam | 11 | 2 |
| Ava | 12 | 2 |
| Charly | 12 | 2 |
| Noah | 13 | 3 |
| Olivia | 13 | 3 |