完全编辑我的问题。因为我想我的第一次尝试太不清楚了。我实际上有三列的表。我需要添加新列并按从开始经过的时间填充它
|| *station_id* || *counter* || *stop* || *time from begining* ||
|| 22500 || 0 || 16:15:00 || ||
|| 22710 || 1 || 17:24:00 || ||
|| 22790 || 2 || 18:10:00 || ||
|| 22670 || 3 || 19:43:00 || ||
|| 22800 || 4 || 21:42:00 || ||
|| 22920 || 5 || 22:47:00 || ||
|| 24050 || 6 || 00:53:00 || ||
|| 24010 || 7 || 02:13:00 || ||
|| 24280 || 8 || 02:30:00 || ||
|| 24270 || 9 || 02:57:00 || ||
|| 24250 || 10 || 03:45:00 || ||
|| 24249 || 11 || 06:45:00 || ||
|| 25270 || 12 || 08:06:00 || ||
|| 1190 || 13 || 09:23:00 || ||
|| 25230 || 14 || 10:43:00 || ||
|| 25201 || 15 || 11:23:00 || ||
|| 25215 || 16 || 11:54:00 || ||
|| 24605 || 17 || 13:05:00 || ||
|| 24577 || 18 || 13:44:00 || ||
|| 24580 || 19 || 14:23:00 || ||
|| 24583 || 20 || 15:09:00 || ||
|| 24585 || 21 || 15:40:00 || ||
|| 24610 || 22 || 16:40:00 || ||
|| 24850 || 23 || 17:47:00 || ||
|| 24840 || 24 || 18:12:00 || ||
|| 24500 || 25 || 21:32:00 || ||
|| 24760 || 26 || 00:52:00 || ||
|| 24100 || 27 || 06:23:00 || ||
|| 24791 || 28 || 08:55:00 || ||
|| 24938 || 29 || 10:05:00 || ||
|| 24943 || 30 || 10:34:00 || ||
|| 21602 || 31 || 11:52:00 || ||
|| 21609 || 32 || 14:58:00 || ||
|| 21800 || 33 || 16:32:00 || ||
|| 21630 || 34 || 17:13:00 || ||
|| 21646 || 35 || 18:02:00 || ||
|| 21640 || 36 || 18:55:00 || ||
|| 21650 || 37 || 19:15:00 || ||
|| 21670 || 38 || 20:38:00 || ||
|| 21654 || 39 || 21:13:00 || ||
|| 21680 || 40 || 21:35:00 || ||
|| 21658 || 41 || 22:39:00 || ||
|| 21600 || 42 || 01:11:00 || ||
|| 21760 || 43 || 03:09:00 || ||
|| 27580 || 44 || 04:43:00 || ||
|| 27453 || 45 || 05:14:00 || ||
|| 27570 || 46 || 05:34:00 || ||
|| 27560 || 47 || 06:22:00 || ||
|| 27438 || 48 || 06:52:00 || ||
|| 27550 || 49 || 07:53:00 || ||
|| 27530 || 50 || 09:04:00 || ||
|| 27200 || 51 || 11:14:00 || ||
|| 27240 || 52 || 14:08:00 || ||
如何更新它,并提出最后一个问题,从计数器 = 0 的车站过去了多少分钟。
我的错误尝试如下所示:
select station_id,counter, stop_ends,
IF(TIMEDIFF(stop_ends, @diff := (select (stop_ends) from route ri where ri.train_id=ro.train_id and counter=0)) >= 0, TIMEDIFF(stop_ends, @diff),
SEC_TO_TIME(
TIME_TO_SEC(TIMEDIFF('23:59:59', @diff)) + 1 +
TIME_TO_SEC(TIMEDIFF(stop_ends, '00:00:00')))
)
as travel
from route ro where train_id = 1130 order by counter
它完美地估计了时间,但仅限于第一天。