SQLで累積を計算する場合、OVER句を利用すると便利
1時間毎の雨量を INSERT datetime, precipitation 2018-06-01 00:00, 0.0 2018-06-01 01:00, 0.1 2018-06-01 02:00, 0.3 ....... 2018-06-30 22:00 1.2 2018-06-30 23:00 1.3
datetime を昇順でソートし、降水量累計 [sql] SELECT datetime, precipitation, SUM(precipitation) OVER(ORDER BY datetime ASC) AS sum_precipitation FROM rainfalls WHERE datetime >= '2018-06-01 00:00' AND datetime < '2018-07-01 00:00' ORDER BY datetime [/sql]
datetime, precipitation, sum_precipitation 2018-06-01 00:00, 0.0, 0.0 2018-06-01 01:00, 0.1, 0.1 2018-06-01 02:00, 0.3, 0.4 ....... 2018-06-30 22:00 1.2, 11.1 2018-06-30 23:00 1.3, 12.4