Divide rows in a window partition into a specified number of ranked buckets (tiles) as evenly as possible, returning the bucket number for each row.
Divides rows into N roughly equal groups and assigns a bucket number (1 to N) to each row. Useful for creating quartile, quintile, or decile buckets for analysis and bucketed sampling.
Compatibility
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | Native | 8.0 | NTILE(n) added in MySQL 8.0. Distributes rows into n buckets. If rows don't divide evenly, earlier buckets get one extra row. NTILE(100) = percentile bucket. |
| PostgreSQL | Native | 8.4 | Standard NTILE(n). Supports the WINDOW clause shorthand for reusing window definitions. |
| SQL Server | Native | 2005 | Standard NTILE(n). Available since SQL Server 2005. |
| Oracle | Native | 8i | Standard NTILE(n). Available since 8i. |
| SQLite | Native | 3.25.0 | NTILE(n) added in SQLite 3.25.0. |
Details
NTILE is universally supported across all engines (post MySQL 8.0). The bucket distribution rule for uneven splits is consistent: earlier buckets get the extra row. NTILE(100) gives approximate percentile buckets; for true percentiles use PERCENTILE_CONT() WITHIN GROUP.
Standard Syntax
Version Support
Per-Database Syntax & Notes
MySQL Native syntax
NTILE(n) added in MySQL 8.0. Distributes rows into n buckets. If rows don't divide evenly, earlier buckets get one extra row. NTILE(100) = percentile bucket.
PostgreSQL Native syntax
Standard NTILE(n). Supports the WINDOW clause shorthand for reusing window definitions.
SQL Server Native syntax
Standard NTILE(n). Available since SQL Server 2005.
Oracle Native syntax
Standard NTILE(n). Available since 8i.
SQLite Native syntax
NTILE(n) added in SQLite 3.25.0.