Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql GTFS数据-停止数据_Mysql_Sql_Join_Gtfs - Fatal编程技术网

Mysql GTFS数据-停止数据

Mysql GTFS数据-停止数据,mysql,sql,join,gtfs,Mysql,Sql,Join,Gtfs,目前对我的SQL技能感到有些生疏。我想实现的是将两个SQL查询连接到一个查询中,它基本上为我提供了有关特定stop的所有信息 第一个查询很简单。它需要所有的停止信息。我会说是小菜一碟;) 第二个有点复杂,但我在这里找到了我的解决方案,并且做了一些小的改动,就像我想要的一样 select GROUP_CONCAT( distinct rt.route_short_name) as routes from routes rt, trips tr, stop_times st where rt.rou

目前对我的SQL技能感到有些生疏。我想实现的是将两个SQL查询连接到一个查询中,它基本上为我提供了有关特定stop的所有信息

第一个查询很简单。它需要所有的停止信息。我会说是小菜一碟;)

第二个有点复杂,但我在这里找到了我的解决方案,并且做了一些小的改动,就像我想要的一样

select GROUP_CONCAT( distinct rt.route_short_name) as routes
from routes rt, trips tr, stop_times st
where rt.route_id = tr.route_id
and tr.trip_id = st.trip_id
and st.stop_id = 97
现在,我想在第一个查询结果中添加第二个查询结果作为另一列。感谢在json_编码之后,我将拥有漂亮的json和我需要的所有信息


谢谢

您可以使用锤子法:

SElECT * FROM (
   SELECT stop_id, stop_name, stop_lat, stop_lon, zone_id 
   FROM stops WHERE stop_id = 97
) a INNER JOIN (
   select st.stop_id, GROUP_CONCAT( distinct rt.route_short_name) as routes
   from routes rt, trips tr, stop_times st
   where rt.route_id = tr.route_id
   and tr.trip_id = st.trip_id
   and st.stop_id = 97
) b ON a.stop_id = b.stop_id
或者加入他们:

select stops.stop_id, 
stops.stop_name, 
stops.stop_lat, 
stops.stop_lon, 
stops.zone_id, 
GROUP_CONCAT( distinct rt.route_short_name) as routes
from routes rt, trips tr, stop_times st, stops
where rt.route_id = tr.route_id
and tr.trip_id = st.trip_id
and st.stop_id = stops.stop_id
and st.stop_id = 97
group by st.stop_id

但是如何加速呢?当我在phpMyAdmin中调用它时,它几乎没什么问题,但在php中它需要很长时间。显然,hammer方法更快:)为了加快查询速度,您必须发布查询和表模式的
explain select…
的输出,以便我们可以查看索引。但这一切可能更适合于另一个问题。如何在多个搜索结果中添加相同的列,例如,从停止名称“%$search\u term%”在Postgres上也很有用的站点中选择停止id、停止名称、停止纬度、停止长度、区域id,只需稍加修改!只需使用
array\u agg(distinct rt.route\u short\u name)作为路由
select stops.stop_id, 
stops.stop_name, 
stops.stop_lat, 
stops.stop_lon, 
stops.zone_id, 
GROUP_CONCAT( distinct rt.route_short_name) as routes
from routes rt, trips tr, stop_times st, stops
where rt.route_id = tr.route_id
and tr.trip_id = st.trip_id
and st.stop_id = stops.stop_id
and st.stop_id = 97
group by st.stop_id