I have two tables in a MySQL database and I need am interpolation function but I’m not sure how do approach this. The two tables look like:

Table 1 looks something like…

```
+----------+-------+
| speed    | Calc  |
+----------+-------+
|    3     |       |
|    4     |       |
|    5     |       |
|    6     |       |
|    7     |       |
|    8     |       |
|    9     |       |
|    10    |       |
|    11    |       |
|    12    |       |
|    13    |       |
|    14    |       |
|    15    |       |
+----------+-------+

```

Table 2 looks like:

```
+----------+---------+
| speed    |binspeed |
+----------+---------+
|    3     | 29.1835 |
|    5     | 16.7992 |
|    10    | 10.5918 |
|    15    | 8.4319  |
+----------+---------+

```

So pretty much I need to check for each speed in table 1. If the speed matches the `avgBinSpeed` in table 2 then I set `Calc = binspeed`. If the speed is between values, I need to use a function than uses the next lower and higher values such as `calc = lower binspeed + ((table1.speed- lower avgBinSpeed value)/(next avgBinSpeed value))*(next binspeed – lower binspeed)` as the example below for speed 3 and 4.

```
If (Table1.speed = 3)
(update table1 T
Inner join table2 X
On t.speed = x.speed
Set Oregon = binspeed);

If (Table1.speed = 4)
(update table1 T
Inner join table2 X
On t.speed = x.spedd
Set Oregon = (29.1835+((4-3)/(5-3))*( 16.7921-29.1835));

```

This is what I don’t know how to do. Since 4 its between the `avgBinSpeed` of 3 and 5 I need to use the `binspeed of 3 (29.1835) + ((speed (4) – speed (3))/( avgBinSpeed (5) - avgBinSpeed (3))) * (binspeed of 5 (16.7992) – binspeed of 3 (29.1835)`.
How can I approach this problem so I can get something like the table below?

```
+----------+-------+
| speed    | Calc  |
+----------+-------+
|    3     | 29.18352307 |
|    4     | 22.98782107 |
|    5     | 16.79211907 |
|    6     | 15.55207188 |
|    7     | 14.31202469 |
|    8     |       |
|    9     |       |
|    10    |       |
|    11    |       |
|    12    |       |
|    13    |       |
|    14    |       |
|    15    |       |
+----------+-------+

```