gpt4 book ai didi

mysql - 间接路由的 GTFS SQL 查询

转载 作者:行者123 更新时间:2023-11-29 18:52:00 24 4
gpt4 key购买 nike

我需要编写一个查询来查找 GTFS 数据结构中两个站点之间的路线/行程,我已将所有 csv 数据迁移到 mysql 表。这是 stop_times.txt 的示例数据

trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,shape_dist_traveled
170309010001S10,12:24:00,12:24:00,10000871,1,MRT SG BULOH - HOSPITAL SG BULOH,0.00688
170309010001S10,12:28:32,12:28:32,10000872,2,MRT SG BULOH - HOSPITAL SG BULOH,1.249023
170309010001S10,12:29:57,12:29:57,10002386,3,MRT SG BULOH - HOSPITAL SG BULOH,1.595181
170309010001S10,12:31:58,12:31:58,10000874,4,MRT SG BULOH - HOSPITAL SG BULOH,2.113874
170309010001S10,12:33:45,12:33:45,10000875,5,MRT SG BULOH - HOSPITAL SG BULOH,2.56561

我无法进行查询来返回间接路线的所有行程,任何帮助将不胜感激。

最佳答案

如果您只想要两站之间的 Trip.Id 和 Route.Id。

select StopTimes.TripId , Trips.RouteId
from StopTimes
join Trips on (Trips.Id = StopTimes.TripId)
Where TripId in
(
select StopTimes.TripId
from StopTimes
Where StopTimes.StopId = FirstStopId
)
And StopTimes.StopId = SecondStopId

请记住,要在 StopTimes.TripId 上创建索引。

关于mysql - 间接路由的 GTFS SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44325493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com