SQL Taskbook Level 8.1
The tables are given:
| id | customer_id | order_date | total_amount |
|---|---|---|---|
| 1 | 2 | 2023-11-11 | 7500 |
| 2 | 1 | 2023-09-30 | 9000 |
| 3 | 2 | 2023-09-09 | 3200 |
| 4 | 1 | 2023-09-12 | 6700 |
| 5 | 2 | 2023-09-27 | 5500 |
| 6 | 3 | 2023-10-06 | 8200 |
| 7 | 4 | 2023-10-10 | 7300 |
| 8 | 5 | 2023-11-05 | 1200 |
| 9 | 4 | 2023-11-10 | 3600 |
| 10 | 1 | 2023-10-11 | 4500 |
| id | name |
|---|---|
| 1 | John |
| 2 | Andrew |
| 3 | Kevin |
| 4 | Mark |
| 5 | Eric |
Solve the following tasks for them:
You need to find the customer with the longest period between their first and last order. Print their name, the date of their first order, and the date of their last order.
Modify the problem so that you find the customers with the highest order amount for each year. Print the customer's name, year, and order amount.