Chapter 8 · Window Functions
02. Customer Order Sequence Numbers
Medium20 XPE-Commerce
For each customer, assign a sequence number to their orders in chronological order (1st order, 2nd order, etc.). Return customer_id, order_id, order_date, total_amount, and the order_sequence_number. If a customer placed two orders on the same date, the lower order id comes first. Sort by customer_id, then order_sequence_number.
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.