我在
MySQL数据库中有两个表,我需要插值函数,但我不确定如何处理它.这两个表看起来像:
表1看起来像……
+----------+-------+
| speed | Calc |
+----------+-------+
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
+----------+-------+
表2看起来像:
+----------+---------+
| speed |binspeed |
+----------+---------+
| 3 | 29.1835 |
| 5 | 16.7992 |
| 10 | 10.5918 |
| 15 | 8.4319 |
+----------+---------+
所以我需要检查表1中的每个速度.如果速度与表2中的avgBinSpeed匹配,那么我设置Calc = binspeed.如果速度介于值之间,我需要使用一个函数而不是使用下一个更低和更高的值,例如calc = lower binspeed((table1.speed- lower avgBinSpeed value)/(next avgBinSpeed value))*(next binspeed – lower binspeed)以下为速度3和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));
这是我不知道该怎么办.因为它在avgBinSpeed 3和5之间我需要使用3的速度(29.1835)((速度(4) – 速度(3))/(avgBinSpeed(5) – avgBinSpeed(3)))*(binspeed of 5(16.7992) – 3(29.1835)的binspeed.
我怎样才能解决这个问题所以我可以得到类似下表的内容?
+----------+-------+
| 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 | |
+----------+-------+