[]
        
(Showing Draft Content)

NTILE

This function divides a partition into N buckets and assigns each row in the partition its bucket number. It does not accept window frame definitions, such as FRAMEROWS and FRAMERANGE.

Syntax

NTILE(n)

Arguments

The function provides the following argument.

Argument

Description

n

[required] The count of buckets.

The N should be a positive integer and the bucket number starts from 1. If the number of rows within the partition cannot be divisible by the N, the buckets will come in two sizes. The larger buckets come before the smaller buckets. If N is greater than or equal to the number of rows, every row is treated as a bucket.

Example

// WINDOW(NTILE(3), ORDERBY([sold]))

city     |    sold    |    ntile
----------------------------------------------
Paris         100           1
Berlin        150           1
Rome          200           2
Moscow        200           2
London        300           3