4

可能な限り最も効率的なデータベースを考え出そうとしています。私のバス路線はすべて約 10 か所の停留所があります。バスは 1 番から始まり、10 番目の停留所に到着すると、再び戻ってきます。このサイクルは 1 日 3 回発生します。

バスの時間を効率的に生成する方法と、停留所をどこに格納する必要があるかについて、私は本当に行き詰まっています。すべてのストップを 1 つのフィールドに入れ、時刻を別のフィールドに入れると、データベースはあまり動的になりません。

すべてのストップを 1 列に 1 つずつ保存し、次に時間を別の列に保存すると、1 つのストップが複数回あるため、さらに下に多くの繰り返しが発生します。

SQL の学習を始めたばかりで、これが設定されたタスクです。

前もって感謝します。

4

3 に答える 3

3

あなたはあなたを含む1つのテーブルが必要になりますTimetable

  • ルートID
  • ストップID
  • 時間
  • 必要に応じて他のフィールド(方向、シーケンス番号、ブロック番号など)

Bus Stop(停車地名、緯度/経度などRouteを保存するために)と(ルート名、最初の停車地、最後の停車地、方向などを保存するために)別々のテーブルを作成することをお勧めします。

あなたはおそらくこれをすでに知っているでしょうが、バスのスケジューリングは非常にすぐに複雑になる可能性があります。例えば:

  • 印刷されたスケジュールに表示される「時点」として特定の停車地を指定する必要がある場合があります

  • 各ルートには複数のバリエーションがあります。たとえば、一部のバージョンは別のバス停で開始または終了する場合があります

  • スケジュールはおそらく土曜日と日曜日で異なり、ほとんどの代理店は四半期ごとにスケジュールを変更します

これらのケースのいくつかを考慮して、スキーマに組み込む必要がある場合があります。

それは役に立ちますか?

于 2010-03-23T21:32:55.613 に答える
2

Here's just one (of the many) ways to do this:

It sounds like you probably want to have a routes table, which describes each route, and has a start time.

Then, a stops table with descriptions and wait times for the bus at each stop.

A stopDistanceMapping table would describe the distance between two stops, and the drive time between them.

Finally, your routeMap table will link individual routes with a list of stops. You can then fill your routes table distance and time in using the wait time from each individual stop, and the times/distances from stopDistanceMapping.

Good luck!

于 2010-03-23T21:36:25.870 に答える
0

On a (very rough) 1st pass, I would keep the bus route times in a table like this:

RouteID StartingLocationID  EndingLocationID TravelTime

Also I would keep a table of stops such as:

StopID Address City etc... (whatever other information you need about each location)

For the routes themselves I would store:

RouteID StartingLocationID RouteStartTime

Obviously you should tailor this to your own needs, but this should give you a place to start.

于 2010-03-23T21:35:43.517 に答える