Created
October 9, 2024 14:33
-
-
Save sonkol/ee6ff89ce52821b226853af52bac0ad5 to your computer and use it in GitHub Desktop.
Given a stop from which connections departure, return a list of following stops
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
-- Query GTFS tables | |
SELECT DISTINCT | |
x.stop_id, | |
next_stop, | |
stops.stop_name | |
FROM | |
( | |
SELECT | |
stop_id, | |
stop_sequence, | |
LEAD (stop_id) OVER (PARTITION BY trip_id ORDER BY CAST(stop_sequence AS INTEGER)) next_stop | |
FROM stop_times | |
) AS x | |
JOIN | |
stops on next_stop = stops.stop_id | |
WHERE -- comment these lines | |
x.stop_id = "U100Z1P" -- to get a complete set of pairs | |
ORDER BY | |
x.stop_id, next_stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment