Chapter 9 · Interview Level
44. Customer Consecutive Order Month Streaks
Hard40 XPE-Commerce
Find the longest streak of consecutive months in which each customer placed at least one order. A streak breaks when a customer has no orders in a month. Return customer_id and their longest_streak (in months). Sort by longest_streak descending.
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.