NTILE divides ordered rows into groups
NTILE splits ordered rows into a chosen number of nearly equal groups. NTILE(4) creates four groups, often called quartiles. ORDER BY inside OVER decides which rows land near the beginning or end of those groups.
A tiny example
In plain English: Show me every student's name with which quarter of the score range they fall into.
SELECT name, NTILE(4) OVER (ORDER BY score) AS quartile
FROM students;What comes back
| name | quartile |
|---|---|
| Amy | 1 |
| Ravi | 2 |
| Theo | 3 |
| Nia | 4 |
Scores sorted low to high and split into four groups, so Amy lands in quartile 1 and Nia in 4.
Related SQL lessons
Ready for a break?
Take on today's cozy puzzle. A fresh, bite-sized query waits every morning — no timers, no pressure.
play today's sip