作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用标准的 GTFS 数据库,我尝试将行程最后一站的名称添加到我当前的查询中,该查询返回以下内容:
| trip_id | service_id | departure_stop | departure_time | arrival_stop | arrival_time | end_departure |
|---------------------------------|------------|----------------|----------------|-----------------|--------------|---------------|
| 15693832.T6.2-EPP-E-mjp-1.11.R | T6_1 | Clifton Hill | 04:56:00 | Flinders Street | 05:07:00 | 05:07:00 |
等等。
我当前的查询是:
select `t`.`trip_id`,
`c`.`service_id`,
`start_s`.`stop_name` as `departure_stop`,
`start_st`.`departure_time`,
`end_s`.`stop_name` as `arrival_stop`,
`end_st`.`arrival_time`,
`end_st`.`departure_time` as `end_departure`
from `trips` as `t`
inner join `calendar` as `c` on `t`.`service_id` = `c`.`service_id`
inner join `routes` as `r` on `t`.`route_id` = `r`.`route_id`
inner join `stop_times` as `start_st` on `t`.`trip_id` = `start_st`.`trip_id`
inner join `stops` as `start_s` on `start_st`.`stop_id` = `start_s`.`stop_id`
inner join `stop_times` as `end_st` on `t`.`trip_id` = `end_st`.`trip_id`
inner join `stops` as `end_s` on `end_st`.`stop_id` = `end_s`.`stop_id`
where `start_st`.`departure_time` > '00:00:00'
and `start_st`.`departure_time` < '23:59:59'
and `start_s`.`stop_id` = 19974
and `end_s`.`stop_id` = 19854
and start_st.departure_time < end_st.arrival_time
order by arrival_time asc
我一直在努力弄清楚如何在 stop_times
表中获取我的查询为每一行返回的 trip_id
的最后一站。
所以除了我目前拥有的,我还想:
stop_times
表中获取该 trip_id
的最后一个 stop_id
stops
表中获取相应 stop_id
的 stop_name
last_stop
更新:
我尝试选择 s.stop_name
并添加以下内部联接:
inner join (
SELECT s.stop_name, trip_id
FROM stop_times
INNER JOIN stops as s on `s`.`stop_id` = `stop_times`.`stop_id`
ORDER BY stop_sequence DESC
) s on `t`.`trip_id` = `s`.`trip_id`
但是,这会为行程中的每一站添加额外的行,我只想要最后一站,添加 LIMIT 1
不会返回任何结果。
最佳答案
请注意,到达和离开时间可能晚于 GTFS 规范中的午夜(小时值可能是 24、25 等)
select "t"."trip_id",
"c"."service_id",
"start_s"."stop_name" as "departure_stop",
"start_st"."departure_time",
"end_s"."stop_name" as "arrival_stop",
"end_st"."arrival_time",
"end_st"."departure_time" as "end_departure",
"last_st"."arrival_time" as "last_arrival",
"last_s"."stop_name" as "last_stop"
from "trips" as "t"
inner join "calendar" as "c" on "t"."service_id" = "c"."service_id"
inner join "routes" as "r" on "t"."route_id" = "r"."route_id"
inner join "stop_times" as "start_st" on "t"."trip_id" = "start_st"."trip_id"
inner join "stops" as "start_s" on "start_st"."stop_id" = "start_s"."stop_id"
inner join "stop_times" as "end_st" on "t"."trip_id" = "end_st"."trip_id"
inner join "stops" as "end_s" on "end_st"."stop_id" = "end_s"."stop_id"
inner join "stop_times" as "last_st" on "t"."trip_id" = "last_st"."trip_id"
inner join "stops" as "last_s" on "last_st"."stop_id" = "last_s"."stop_id"
where "start_s"."stop_id" = '245' -- my data's stop id
and "end_s"."stop_id" = '762' -- my data's stop id
and "last_st"."stop_sequence" = (select max("stop_sequence") from "stop_times" where "t"."trip_id" = "trip_id")
and start_st.departure_time < end_st.arrival_time
order by arrival_time asc
关于mysql - GTFS 获得旅行的最后一站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32327925/
我正在制作一个应用程序,我在其中为每个国家/地区分配不同的值并根据该值执行某些操作。喜欢: Argentina 3 Australia 7 USA 23 要选择国家/地区,我需要使用用户当前所在的国家
这里是一般 Node mongodb 问题。 我有这个功能: static addSpaceToCreator = ( userId, spaceId, callback ) => {
Linux 中的 tcp 数据路径是否有很好的概述(2.6,如果路径实际不同则不是 2.4)?在 tcp/ip 堆栈处理的不同阶段,数据包在哪里? 数据包如何打包到tcp段,然后是ip数据包。它是如何
我是一名优秀的程序员,十分优秀!