A bookstore wants to find customers who started and finished their buying history with a big haul. Group each customer's purchases by calendar day. A customer's first purchase day is their earliest such day and their last purchase day is their latest. A customer qualifies when the total quantity of books bought on the first day is at least 3 and the total on the last day is also at least 3. Customers whose purchases all happened on a single day have no separate last day and never qualify. Write an SQL query that returns customer_id, first_day_books and last_day_books for every qualifying customer. Order the results by customer_id ascending.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.