SQLQuokka
Start practicing
QuestionsLearnSandboxFeaturesRoadmapFAQ

Amazon: Customer Spend Quartiles

Unsolved

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.

SQL Query Editor (Ctrl+Enter to run)
0 characters · Valid
Canonical Solution Official

Official Solution is Hidden

Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.

Community Q&A & Discussion

Ask questions, share alternate queries, and explore solutions

0 comments
Asked By:
🏢 Amazon

Submission History

Your recent query executions and answer checks

Execution Pipeline:
FROM orders
Full source dataset
12 rows total
Ready. Type a query to see live execution.
Clause: Auto-Sync · AlaSQL Engine