Amazon Customer Lifetime Value modeling segments buyers into 4 spending tiers. Write a SQL query using the `NTILE(4)` window function to partition all purchasing customers into four spend quartiles (1 to 4) ordered by their total spending descending (highest spenders assigned to quartile 1, lowest to quartile 4). If the customer count is not divisible by 4, NTILE assigns the extra members to the top quartiles. Return `customer_id`, `total_spend`, and `spend_quartile`. Order by `spend_quartile ASC`, `total_spend DESC`, and `customer_id ASC`. Note: Window function support requires DuckDB / full SQL engine capabilities. This question is staged for the upcoming DuckDB browser engine.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.