Bucket ordered rows into four groups.

Section: Ranking functions

Split rows into quartiles with NTILE

sql
sql
SELECT customer_id,
       lifetime_value,
       NTILE(4) OVER (ORDER BY lifetime_value DESC) AS quartile
FROM customers;
Explanation

`NTILE` is handy for quick segmentation such as quartiles or deciles.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Ranking functions
ROW_NUMBER
Unique sequence with no ties.
OpenIn sheetsqlsame section
RANK
Tied rows share rank and leave gaps.
OpenIn sheetsqlsame section
DENSE_RANK
Tied rows share rank without gaps.
OpenIn sheetsqlsame section
Calculate percent rank
Relative position from 0 to 1.
OpenIn sheetsqlsame section
Cumulative distribution
Fraction of rows at or below the current row.
OpenIn sheetsqlsame section
Get the latest row per group
Use ROW_NUMBER in a subquery or CTE.