← 返回 amazon 的题目列表Retrieve Every Merchant ID the First Order for Each Date
类型:online_judge
Given a database table orders containing fields: merchant_id, order_date, order_id, write a SQL query to retrieve the merchant ID for the first order on each date. Assume that order_date is formatted as YYYY-MM-DD. Output fields should include: merchant_id, order_date, first_order_id.
Example input:
orders
| merchant_id | order_date | order_id |
|-------------|------------|----------|
| 1 | 2023-03-01 | 101 |
| 2 | 2023-03-01 | 102 |
| 1 | 2023-03-02 | 103 |
| 1 | 2023-03-01 | 104 |
| 2 | 2023-03-02 | 105 |
Example output:
| merchant_id | order_date | first_order_id |
|-------------|------------|----------------|
| 1 | 2023-03-01 | 101 |
| 2 | 2023-03-01 | 102 |
| 1 | 2023-03-02 | 103 |
| 2 | 2023-03-02 | 105 |
Example
Input
orders
| merchant_id | order_date | order_id |
| 1 | 2023-03-01 | 101 |
| 2 | 2023-03-01 | 102 |
| 1 | 2023-03-02 | 103 |
| 1 | 2023-03-01 | 104 |
| 2 | 2023-03-02 | 105 |