Skip to content

Instantly share code, notes, and snippets.

@sonkol
Created October 22, 2024 17:34
Show Gist options
  • Save sonkol/06d637ce97c632c24fbd4a39b93e9ae7 to your computer and use it in GitHub Desktop.
Save sonkol/06d637ce97c632c24fbd4a39b93e9ae7 to your computer and use it in GitHub Desktop.
List stops that chosen routes stop at
SELECT DISTINCT
stop_id,
stop_name,
group_concat(DISTINCT route_short_name ORDER BY cast(route_id AS INT)) routes,
group_concat(DISTINCT trip_headsign ORDER BY cast(route_id AS INT)) headsigns
FROM stop_times
INNER JOIN stops using (stop_id)
INNER JOIN trips using (trip_id)
INNER JOIN routes using (route_id)
WHERE trip_operation_type = 1 -- do not list services in/outbound of depots
AND pickup_type <> 1 -- list only services that actually stop at the stop
AND route_short_name IN (58,59) -- list of routes that stop in the stop together
GROUP BY stop_id
-- HAVING routes = '58,59' -- list only stops that are served by these routes exclusively
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment