作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我只需要能够显示接下来几辆公交车的到达时间,不打算做任何旅行计划。
在单个条目中包含每条路线的所有时间对于数据库来说可能会更快,对吗?尽管这意味着任何正在拖延的时间表都需要得到全部,即使他们只需要一些。
哪种方式效率更高?
最佳答案
在最简单的形式中,您需要三张表:一张用于公交车,一张用于停靠站,一张用于时间表。
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/
我是一名优秀的程序员,十分优秀!