001Level 1

Chapter 7 · CTEs

10. Multi-Step CTE: Customer Value Tiers

Hard40 XPE-Commerce

Build a customer value analysis using multiple CTEs. Step 1: Calculate each customer's total orders and total spending. Step 2: Compute the overall average orders and average spending. Step 3: Classify each customer as 'High Value' (above average in both metrics), 'Medium Value' (above average in one metric), or 'Low Value' (below average in both). Return customer_id, total_orders, total_spending, and value_tier, sorted by total_spending (highest first).

Tables

  • PKidINT
  • FKcustomer_id→ customers.idINT
  • order_dateTEXT
  • statusTEXT
  • total_amountREAL

Need help?

Ask Sol

AI tutor — looks at your current query and nudges you, without spoiling the answer.

Solution

Try the hints first — solving it yourself is what makes it stick.

Peek at the solution?

You can still earn the XP afterwards by submitting a working query — but you'll learn more if you give it one more try.