Skip to content

Instantly share code, notes, and snippets.

@denysvitali
Created April 24, 2018 21:28
Show Gist options
  • Save denysvitali/6266b9f045db3463b9d3ae204a6a6d1e to your computer and use it in GitHub Desktop.
Save denysvitali/6266b9f045db3463b9d3ae204a6a6d1e to your computer and use it in GitHub Desktop.
WITH stops_time AS (
WITH stops_in_region AS (
SELECT s.uid, s.id, s.feed_id FROM stop as s
WHERE
ST_Within(
s.position::geometry,
ST_MakeEnvelope(
5.9559,45.818, 10.4921, 47.8084,
4326)
)
)
SELECT DISTINCT st.trip_id, st.feed_id FROM stop_time as st
INNER JOIN stops_in_region as sir ON sir.id = st.stop_id AND sir.feed_id = st.feed_id
)
SELECT trip.uid FROM stops_time as sst
INNER JOIN trip ON sst.trip_id = trip.trip_id AND sst.feed_id = trip.feed_id
WHERE trip.feed_id = sst.feed_id AND trip.trip_id = sst.trip_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment