Im working with GTFS dataset that I have imported into MySql, Im accessing it with PHP. Im trying to find the trips for a specific route for a given time and date. My Sql query looks like this
'SELECT t.route_id AS route_id, t.service_id AS service_id, t.trip_headsign AS trip_headsign,
t.trip_id AS trip_id,
( SELECT departure_time
FROM stop_times
WHERE trip_id = t.trip_id
ORDER BY departure_time ASC limit 1) AS initial_departure_time,
( SELECT arrival_time
FROM stop_times
WHERE trip_id = t.trip_id
ORDER BY arrival_time DESC limit 1) AS final_arrival_time
FROM trips AS t INNER JOIN calendar_dates AS c
WHERE t.service_id = c.service_id
AND c.date ='.$calendar_date.'
AND initial_departure_time <='.$time.'
AND'.$time. '<=final_arrival_time
AND t.route_id ='.$route.'
ORDER BY trip_id ASC';
$route
, $calendar_date
and $time
are all passed in.
The query is returning Column not found:
1054 Unknown column 'initial_departure_time' in 'where clause'. Im thinking that initial_departure_time cant be evaluated.
Im completely lost as too how to resolve this. Any clues, thanks in advance