I`w got an 2 tables with such data:

Table 1

| id | s\_id | s\_date |
| --- | --- | --- |
| 1 | 33 | 2021-03-05 10:36:59 |
| 2 | 33 | 2021-03-06 10:36:59 |
| 3 | 33 | 2021-03-09 10:36:59 |
| 4 | 33 | 2021-03-10 13:36:59 |
| 5 | 33 | 2021-03-11 12:36:59 |
| 6 | 33 | 2021-03-12 09:00:59 |
| 7 | 33 | 2021-03-13 13:36:59 |
| 8 | 33 | 2021-03-14 18:00:00 |
| 9 | 33 | 2021-03-15 18:00:00 |
| 10 | 33 | 2021-03-16 13:00:00 |
| 11 | 33 | 2021-03-17 18:00:00 |
| 12 | 33 | 2021-03-18 14:00:00 |
| 13 | 33 | 2021-04-01 18:00:00 |
| 14 | 33 | 2021-05-02 14:00:00 |

Table 2

| id | s\_id | amount | date\_from | date\_to |
| --- | --- | --- | --- | --- |
| 1 | 33 | 100 | 2012-03-12 00:00:00 | 2022-01-01 00:00:00 |
| 2 | 33 | 200 | 2018-03-12 00:00:09 | 2021-02-28 00:00:00 |
| 3 | 33 | 300 | 2021-03-01 00:00:00 | 2021-03-31 00:00:00 |
| 4 | 33 | 400 | 2021-03-07 00:00:00 | 2021-03-12 00:00:00 |

How to select row with appropriate id where s\_date between date\_from and date\_to most close to date\_from\date\_to range?
In my case most appropriate rows must be:

| id | s\_id | s\_date | amount |
| --- | --- | --- | --- |
| 1 | 33 | 2021-03-05 10:36:59 | 300 |
| 2 | 33 | 2021-03-06 10:36:59 | 300 |
| 3 | 33 | 2021-03-09 10:36:59 | 400 |
| 4 | 33 | 2021-03-10 13:36:59 | 400 |
| 5 | 33 | 2021-03-11 12:36:59 | 400 |
| 6 | 33 | 2021-03-12 09:00:59 | 400 |
| 7 | 33 | 2021-03-13 13:36:59 | 300 |
| 8 | 33 | 2021-03-14 18:00:00 | 300 |
| 9 | 33 | 2021-03-15 18:00:00 | 300 |
| 10 | 33 | 2021-03-16 13:00:00 | 300 |
| 11 | 33 | 2021-03-17 18:00:00 | 300 |
| 12 | 33 | 2021-03-18 14:00:00 | 300 |
| 13 | 33 | 2021-04-01 18:00:00 | 100 |
| 14 | 33 | 2021-05-02 14:00:00 | 100 |

Thank you!