我只需要能够显示接下来几辆公交车的到达时间,不打算做任何旅行计划。
在单个条目中包含每条路线的所有时间对于数据库来说可能会更快,对吗?尽管这意味着任何正在拖延的时间表都需要得到全部,即使他们只需要一些。
哪种方式效率更高?
最佳答案
在最简单的形式中,您需要三张表:一张用于公交车,一张用于停靠站,一张用于时间表。
create table bus (
bus_id int -- primary key
, route_name varchar(64)
)
create table stop (
stop_id int -- primary key
, bus_id int references bus(bus_id)
, address_or_intersection varchar(128)
)
create table timetable (
time_entry_id int -- primary key
, stop_id int references stop(stop_id)
, run_id int
, stop_time time
)
前两个表是不言自明的。下面是第三个表格的示例,该路线包含三个停靠点,早上跑一趟,晚上跑一趟:
bus:
bus_id route_name
------ ----------
1 red arrow
stop:
stop_id bus_id address
------- ------ ---------
1 1 Market St
2 1 North Point
3 1 Stockton
timetable:
time_entry_id stop_id run_id stop_time
------------- ------- ------ ---------
1 1 1 06:15
2 2 1 06:39
3 3 1 07:05
4 1 2 19:03
5 2 2 19:30
6 3 2 19:51
关于mysql - 对于公交车时刻表,我应该为所有公交车准备一个数据表并将时间表存储在一列中,还是为每辆公交车创建单独的表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9270852/