sql - How can I include in schedules today's departures after midnight using GTFS? -
I started with GTFS and ran into a big problem with my SQL query: Code> SELECT *, (some columns in the form of shortcuts) stop_times from left_stimes.trip_id = trips.trip_id Where trips.max_sequence! = Stop_times.stop_sequence trips join and ($ incodes) stop_id and ($ service_ids) trips.service_id and (departure = gt = $ time) and (trips.end_time & gt; = $ time) and (trips.start_time and lt ; = $ Time_plus_3hrs) GROUP by T, L, SAP, SAC, L DESC LIMIT 14
This should show departure from some stops in the next 3 hours. It works but near midnight (eg 23:50) it only captures "today's departure". After midnight it only grabs the "New Day Departure" and the departure from the previous day disappears, because They have departure_time "24:05" (= $ not greater than $ 00:05). Is it possible to use a little light with the same query for the next day UNION? UNION is using, how can I order departure from border to cart?
Trips.start_time and end_time are my helper variables to accelerate SQL query performance, it means sequence1-ARRIVAL_TIME and MAXsequence-departure of any trip
unions
to be used to link a query each day It is your best bet, as long as you do not want to release two completely different questions and then merge the result together in your application. It will not be worth the effort to make an incompatibility necessary to do this with a single SELECT
statement (it is also possible).
A part of the complexity is active here, the service IDs can vary frequently between days, so a different set should be used for each one (How to create this set in SQL is a subsystem And to suggest joining the table, see.)
More complexity arises from the fact that the results of each day should be treated differently: In order to be ordered, we have to subtract twenty four hours from tomorrow (and only) tomorrow.
Try a question like this, after "Pseudo SQL" in your question and assume that you are using MySQL / MariaDB:
, select * SUBTIME (Departure, '24: 00: 00'), from the stop_times stop_times.trip_id = trips.trip_id Where to go trips trips! .max_sequence = stop_times.stop_sequence and ($ incodes) in stop_id and trips.service_id ($ yesterdays_service_ids) and (exit> gt; ADDTIME ($ time, '24: 00: 00 ')) and (trips.end_time & gt; = ADDTIME ($ time, '24: 00: 00 ')) and select the union (trips.start_time & lt; = ADDTIME ($ time_plus_3hrs, '24: 00: 00')), t as departure_ time. .. ... join the left from stop_times at stop_times.trip_id = trips.trip_id ps where trips.max_sequence = stop_times.stop_sequence and ($ incodes) stop_id and ($ todays_service_ids) and (departure = gt; = time) trips Service_id! And (trips.end_time & gt; = $ time) and (trips.start_time and lt; = $ time_plus_3hrs) group by T, L, SAP, SAC, LDESS LIMIT 14
Comments
Post a Comment