SQLite NTILE() Function
Example
Split the products into four price groups:
SELECT ProductName, Price,
NTILE(4) OVER (ORDER BY Price) AS PriceGroup
FROM Products;
Try it Yourself »
Definition and Usage
The NTILE() function splits the rows into a given number of groups, as equal in size as possible, and returns the group number of each row, starting with 1.
Note: Window functions need an OVER clause. Read more in the SQLite Window Functions chapter.
Syntax
NTILE(n) OVER (ORDER BY column)
Parameter Values
| Parameter | Description |
|---|---|
| n | Required. The number of groups |
Technical Details
| Return type: | Integer |
|---|---|
| Works in: | SQLite 3.25.0 and later |