计算每小时潮位

时间:2016-09-14 04:22:50

标签: mysql

我在MYSQL中有一个包含每日高/低潮位的表:

+-----+---------------------+------+---------+
| ID  | Date                | Feet | HighLow |
+-----+---------------------+------+---------+
| 960 | 2016-09-13 05:55:00 |  0.2 | L       |
| 961 | 2016-09-13 12:56:00 |  2.5 | H       |
| 962 | 2016-09-13 19:21:00 |  0.6 | L       |
| 963 | 2016-09-14 00:35:00 |  1.7 | H       |
+-----+---------------------+------+---------+

我想扩展此表,以包含当天每小时的近似潮位。我有一个查询,它给出了潮汐之间的小时数(十进制格式)和水平的变化(以英尺为单位):

select
  t.date,
  t.feet,
  t.highlow,
  time_to_sec(timediff(t.date, @lastdt )) / 3600 as 'dif',
  if(t.feet IS NOT NULL, t.feet - @lastft, 000 ) as 'ft',
  @lastdt := t.date,
  @lastft := t.feet

from
  tides t,
  ( select @lastdt := 0,
           @lastft := 0 ) SQLVars

order by
  t.date);

结果如下:

+---------------------+------+---------+--------+------+
| date                | feet | highlow | dif    | ft   |
+---------------------+------+---------+--------+------+
| 2016-09-13 05:55:00 |  0.2 | L       | 6.0333 | -1.2 |
| 2016-09-13 12:56:00 |  2.5 | H       | 7.0167 |  2.3 |
| 2016-09-13 19:21:00 |  0.6 | L       | 6.4167 | -1.9 |
| 2016-09-14 00:35:00 |  1.7 | H       | 5.2333 |  1.1 |
+---------------------+------+---------+--------+------+

我一直无法弄清楚如何将潮汐量(ft)除以潮汐之间的小时数(dif)以获得每小时的潮汐变化;然后按小时增量添加。

我想从上表中看到的输出示例: 2.3 / 7.0 = .33(英尺/小时)

+---------------------+------+
| date                | feet |
+---------------------+------+
| 2016-09-13 05:55:00 |  0.2 |
| 2016-09-13 06:55:00 |  0.5 |
| 2016-09-13 07:55:00 |  0.8 |
| 2016-09-13 08:55:00 |  1.1 |
| 2016-09-13 09:55:00 |  1.4 |
| 2016-09-13 10:55:00 |  1.7 |
| 2016-09-13 11:55:00 |  2.0 |
| 2016-09-13 12:56:00 |  2.5 |
+---------------------+------+

任何想法都会非常感激。

0 个答案:

没有答案