Last active
May 12, 2021 19:39
-
-
Save lovasoa/8591217 to your computer and use it in GitHub Desktop.
GTFS: Select stops with associated routes (works on a database build from gtfs files, one table per file) https://developers.google.com/transit/gtfs/reference)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE stop_route_link (stop_id,route_id); | |
INSERT INTO stop_route_link (stop_id, route_id) | |
SELECT DISTINCT stops.stop_id, trips.route_id from stops | |
INNER join stop_times on stop_times.stop_id=stops.stop_id | |
INNER join trips on trips.trip_id=stop_times.trip_id; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select stops.stop_name, routes.route_long_name | |
from stops | |
join stop_route_link on stop_route_link.stop_id=stops.stop_id | |
join routes on routes.route_id=stop_route_link.route_id; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT DISTINCT stops.stop_name, routes.route_long_name from stops | |
INNER join stop_times on stop_times.stop_id=stops.stop_id | |
INNER join trips on trips.trip_id=stop_times.trip_id | |
INNER join routes on routes.route_id=trips.route_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment