Skip to main content
All Problems
hard0% acceptance

Multi-Step CTE: Customer Value Tiers

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.

Schema

🔑idINT
🔗customer_idINT
order_dateTEXT
statusTEXT
total_amountREAL
postgresql

Run your query to see results

Press Ctrl + Enter to execute