在数据库中存储两个位置之间的路线
有人可以告诉我,如何设计一个数据库,可以存储
- 起始位置(城市名称)
- 之间的位置(城市名称黑白起始位置和结束位置) 位置,数据库应该能够处理任意数量的位置)
- 结束位置(城市名称)
谢谢!
编辑:
例如,我必须保存芝加哥和纽约之间的地点。 我不确定如何设计一个可以容纳
- 起始地点(芝加哥)
- 之间位置的数据库(我主要对这里的数据类型感到困惑)
- 结束地点(纽约)
Can some one please tell me, how to design a database that can store
- Starting location ( Name of city)
- Places between ( Name of cities b/w Starting location and Ending
location , db should be able to handle any number of places ) - Ending location ( Name of city )
Thanks !
Edit:
For example I have to Save The places between Chicago and New York.
I am not sure how to design a db that can Hold
- The starting Place ( Chicago )
- places in between ( Iam mainly confused about datatype here )
- Ending place ( New York)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有三个表:位置、路线和停靠点
停靠点表是交叉链接表。在插入位置时,让应用程序设置正确的停止编号。
然后,您可以使用简单的方法获取路线。
如果您需要将位置插入路线,请使用两个查询:
理论上,链接列表(在其中存储对路线上下一站的引用)在概念上更接近现实,但在标准的 Mysql-options 中,从以这种方式存储的数据中获取列表非常困难,所以我建议不要这样做,并让自己保持简单。
如果您确实需要在路线中创建和使用链接节点的更多功能,您可以考虑学习: http://openquery .com/graph/doc,但对于不需要一直重新计算的简单的从开始到结束的路线,上面的内容很可能就足够了。
I'd have three tables: locations, routes and stops
The stops-table is the crosslink table. On inserting locations, have the application set the correct stopnumber.
You can then get your route with a simple
If you ever need to insert a location to a route, use two queries:
In theory a linked list (where you store a reference to the next stop on the route) is conceptually closer to reality, but in the standard Mysql-options it is very difficult to get a list from data that is stored that way, so I would advise against it and keep it simple for yourself.
If you really need more power on creating and using linked nodes in a route, you could consider learning about: http://openquery.com/graph/doc but for simple start-to-finish routes that don't have to be recalculated all the time, the above will most likely suffice.
您应该有另一个可以引用的表,该表与所有开始、中转和结束记录具有一对多关系,因此您可以将整个记录“集合”“绑定”在一起。
行程
地点
在
location_type
列中,您可以有一些独特的标志,这些标志将告诉您位置记录是否表示出发、中转或 >完成。例如,开始可以是0
标志,1
可以是中转标志,2
可以是结束标志。You should have another table you can reference to, which will have a one-to-many relationship with all the start, transit, and finish records, so you can "bind" the whole "collection" of records together.
trips
locations
In the
location_type
column you can have some distinctive flags which will tell you if a record of location denotes starting, transit, or finish. For example, start could be a flag of0
,1
could be a flag of transit, and2
could be a flag of finish.未经测试
Untested