SQL Taskbook Level 8.7 of the SQL task book
The tables are given:
| id | first_name | last_name |
|---|---|---|
| 1 | Joe | Doe |
| 2 | Erick | Brown |
| 3 | Max | Red |
| 3 | Alisa | Green |
| id | first_name | last_name |
|---|---|---|
| 1 | Maison | Molina |
| 2 | Mari | Mathews |
| 3 | Ciaran | Byrd |
| 4 | Levi | Miller |
| 5 | Emre | Benjamin |
| 6 | Kadie | Herrera |
| 7 | Lucas | Hussain |
| 8 | Joe | Solis |
| 9 | James | Curry |
| 10 | Wade | Baldwin |
| id | date | client_id | provider_id |
|---|---|---|---|
| 1 | 2022-01-18 | 2 | 3 |
| 2 | 2022-02-21 | 1 | 3 |
| 3 | 2022-03-31 | 1 | 3 |
| 4 | 2022-04-20 | 2 | 3 |
| 5 | 2022-05-17 | 5 | 2 |
| 6 | 2022-06-15 | 2 | 1 |
| 7 | 2022-07-13 | 9 | 1 |
| 8 | 2022-08-12 | 3 | 2 |
| 9 | 2022-09-09 | 1 | 1 |
| 10 | 2022-10-10 | 3 | 3 |
Solve the following tasks for them:
Find the doctor who has had the most appointments in the last three months. Display their name and the number of appointments.
Find the client who has had the most appointments with the same doctor. Output their name and the number of appointments with that doctor.