How do I use calendar exceptions to generate accurate schedules using GTFS?

安稳与你 提交于 2019-12-02 08:40:02

I'm fairly certain it's not possible to do what you're trying to do with only a single SELECT statement, due to the design of the calendar and calendar_dates tables.

What I do is use a second, inner query to build the set of active service IDs on the requested date, then join the outer query against this set to include only results relevant for that date. Try this:

SELECT DISTINCT ST.departure_time FROM stop_times ST
  JOIN trips T ON T._id = ST.trip_id
  JOIN (SELECT _id FROM calendar
          WHERE start_date <= 20140607
            AND end_date >= 20140607
            AND saturday = 1
          UNION
            SELECT service_id FROM calendar_dates
              WHERE date = 20140607
                AND exception_type = 1
          EXCEPT
            SELECT service_id FROM calendar_dates
              WHERE date = 20140607
                AND exception_type = 2
       ) ASI ON ASI._id = T.service_id
  WHERE ST.stop_id = 3377699724118483 
    AND T.direction_id = 0
    AND ST.departure_time >= "16:00:00"
  ORDER BY ST.departure_time
  LIMIT 20
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!