First Order
Return each customer's first order: the customer_id, and the day and amount of that customer's order with the earliest day. When a customer has two orders on their earliest day, the first is the one with the smaller id. Rows may come in any order.
Example 1
orders
| id | customer_id | day | amount |
|---|---|---|---|
| 1 | 7 | 2026-01-09 | 100 |
| 2 | 8 | 2026-01-03 | 250 |
| 3 | 7 | 2026-01-04 | 30 |
| 5 | 8 | 2026-01-03 | 40 |
returns
| customer_id | day | amount |
|---|---|---|
| 7 | 2026-01-04 | 30 |
| 8 | 2026-01-03 | 250 |
Constraints
- Up to 14 orders
- Ids are unique
Write it in your browser, against the clock. The model query, with a note on each piece of it, comes after.
More SQL problems
- Latest PriceMedium
- More Than the ManagerMedium
- Open PositionsMedium
- Rank in the DepartmentMedium
- Revenue per CityMedium
- Running BalanceMedium
- Second From the TopMedium
- Share of the TotalMedium