Chapter 6 · Subqueries
48. Orders Above Customer's Own Average
Hard40 XPE-Commerce
For each customer, find orders whose total_amount exceeds that specific customer's average order value. Return the customer's full name, order id, total_amount, and their personal average order value. This requires a correlated subquery. Sort by customer name, then total_amount (highest first).
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.