It depends on which method you are using for the calendar and
calendar_dates. If you use the "alternate" method of bypassing the
calendar table it's pretty simple.
select trips.route_id, stop_times.departure_time
from calendar_dates, stop_times, trips
where calendar_dates.date='your_date'
and calendar_dates.exception_type=1
and stop_times.stop_id='your_stop_id'
and calendar_dates.service_id=trips.service_id
and stop_times.trip_id=trips.trip_id;
If you use the "recommended" method combining the calendar and
calendar_dates as exceptions it's more complicated.
select trips.route_id, stop_times.departure_time
from calendar, stop_times, trips
where 'your_date' between calendar.start_date and calendar.end_date
and stop_times.stop_id='your_stop_id'
and calendar.service_id=trips.service_id
and stop_times.trip_id=trips.trip_id
and ( (dayofweek('your_date')=1 and calendar.sunday=1)
or (dayofweek('your_date')=2 and calendar.monday=1)
or (dayofweek('your_date')=3 and calendar.tuesday=1)
or (dayofweek('your_date')=4 and calendar.wednesday=1)
or (dayofweek('your_date')=5 and calendar.thursday=1)
or (dayofweek('your_date')=6 and calendar.friday=1)
or (dayofweek('your_date')=7 and calendar.saturday=1))
and not exists (select 1
from calendar_dates
where calendar_dates.date='your_date'
and calendar_dates.date between
calendar.start_date and calendar.end_date
and
calendar.service_id=calendar_dates.service_id
and calendar_dates.exception_type=2)
union
select trips.route_id, stop_times.departure_time
from calendar_dates, stop_times, trips
where calendar_dates.date='your_date'
and calendar_dates.exception_type = 1
and stop_times.stop_id='your_stop_id'
and calendar_dates.service_id=trips.service_id
and stop_times.trip_id=trips.trip_id;
There may be a more elegant way for the dayofweek part but this should
work (I'm not as familiar with mysql). FYI, TriMet uses the alternate
method because of the simplicity of these types of queries. Hope this
helps.