First Order per Merchant per Date
Updated
Problem statement
The orders table has one row per order: a unique order_id, the merchant_id of the merchant that received it, and the order_time when it was placed.
For every merchant and every calendar date on which that merchant has at least one order, return the merchant's first order of that date. The first order is the one with the earliest order_time. If several orders share the earliest time, pick the one with the smallest order_id.
Return the columns merchant_id, order_date (the date part of order_time), and order_id. Sort the rows by merchant_id and then by order_date, both from smallest to largest.
Table schema
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
orders
One row per order.
| Column | Type | Nullable | Description |
|---|---|---|---|
| order_idPK | Integer | No | — |
| merchant_id | Integer | No | — |
| order_time | Timestamp | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| merchant_id | Integer | No | — |
| order_date | Date | No | — |
| order_id | Integer | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
- The
orderstable has from0to10^5rows. order_idis unique, and1 <= order_id, merchant_id <= 10^9.- No column is
NULL. - Every
order_timeis between2000-01-01 00:00:00and2030-12-31 23:59:59, to the second.
More Amazon Onsite Interview questions
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dungeon GameONSITE INTERVIEW · Seen Nov 2026
- Integer BreakONSITE INTERVIEW · Seen Nov 2026
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Daily USD Totals with Effective-Dated Exchange RatesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Most Recent Order for Each CustomerCapgemini · ONSITE INTERVIEWCapgemini interview questions
- Tenth-Highest Distinct SalaryInfosys · ONSITE INTERVIEWInfosys interview questions
- Fifth Highest Salary In A DepartmentZS · ONSITE INTERVIEWZS interview questions
- In-Memory Database QueriesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Nth-Highest Distinct Salary Without Ranking FunctionsMastercard · ONSITE INTERVIEWMastercard interview questions
- Contest Participants with Long Totals and Short QuestionsThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
- Block Transaction Count TrendsChainalysis · ONSITE INTERVIEWChainalysis interview questions
- Third-Highest Distinct SalaryExpedia · ONSITE INTERVIEWExpedia interview questions
- Highest-Paid Employees in Every DepartmentMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions