Chapter 9 · Interview Level
38. Customer Churn Risk Scoring
Hard40 XPE-Commerce
Build a churn risk report. For each customer, compute: days since last order (from '2025-01-01'), total orders and average order value. Assign risk: 'High' if no order in 90+ days, 'Medium' if 60-89 days, 'Low' otherwise. Show customer_id, first_name, last_name, total_orders, avg_order_value (rounded to 2), days_since_last_order, and risk_level. Sort by days_since_last_order descending.
Tables
- PKidINT
- first_nameTEXT
- last_nameTEXT
- emailTEXT
- phoneTEXT
- cityTEXT
- stateTEXT
- countryTEXT
- created_atTIMESTAMP
- 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.