Code RoomCustomer order date range
HardPrep Room Coding #5118

Customer order date range

SQLAlgorithms & data structuresSenior~13 min

For each order return `id`, `customer_id`, `first_order` and `latest_order`: the earliest and latest order dates for that customer. Order by customer then id.

What a strong answer looks like

Say what the query is meant to return before you write it, and name the shape of the answer: how many rows, grouped by what. Then watch the NULLs and the duplicates, because that is where most of these are lost.

Run onlyA query runs as one statement, so there is nothing to step through. Run it and read the rows.

0:00 of about 13 min

Expected, in this order

idcustomer_idfirst_orderlatest_order
112026-01-042026-03-03
212026-01-042026-03-03
712026-01-042026-03-03
322026-01-212026-02-28
422026-01-212026-02-28
622026-01-212026-02-28

1 more row

Your result

Run your query to compare.

1 more set of rows are waiting. Free with an account.