Turning Learners Into Developers
Codekilla
CODEKILLA
Medium
SQL-W06sql

Bucket Users Into Percentile Quartiles

Problem

Given `users(id, ltv)`, label each user 'Q1'..'Q4' based on LTV quartiles. Q1 = highest 25%, Q4 = lowest 25%. Output (id, ltv, bucket).

Input
users table
Output
id, ltv, bucket
Constraints
1 ≤ rows ≤ 10^6
Sample input
see prompt
Sample output
...
Explanation
NTILE(4) splits an ordered set into 4 equal-sized buckets.
window-fnntilequartile@Snowflake
Visible test cases
in: see
out: ...
Your solution — run it, use AI if stuck
sql