407. High-Value Customers (Top 10%)

Hard Marketing Customer Segmentation
Query Rules
  • The query columns and order must match the expected result schema.
  • NULL values should be handled appropriately where applicable.
  • The grader compares output values and sorting order to evaluate.

Schema Browser

Click a table's header to toggle expand/collapse.
locations
3 cols
departments
3 cols
employees
6 cols
orders
6 cols

Reference Solution

Expected SQL
WITH cust_avg AS (SELECT customer_name, AVG(amount) as avg_spend FROM orders GROUP BY customer_name) SELECT customer_name, avg_spend FROM (SELECT customer_name, avg_spend, NTILE(10) OVER (ORDER BY avg_spend DESC) as decile FROM cust_avg) WHERE decile = 1;
SQL Editor
Ctrl+Enter to run
Console Output

Console Terminal

Write your query and click "Run Query" (Ctrl + Enter) to see results and testcase validation.