Chapter 7 · CTEs
01. Each Customer's First Order
Medium20 XPE-Commerce
For each customer, find their first order. Return the customer's full name, the order_date of their first order, and the total_amount. Use a CTE with ROW_NUMBER to identify the earliest order per customer. Sort by order_date.
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.