how do I design return travel itinerary vs one way itinerary

旧城冷巷雨未停 提交于 2019-12-12 01:52:46

问题


I'm not quite sure how to approach this problem:

  • Price for one-way trips is different than price for round trip itineraries.

In the backend, I have a table for storing the itinerary (which yields an id). I have another pricing table, which defines what is the price of this id from startDate to endDate.

My itinerary table can only represent information for one way travel. How do I model round trip itineraries ?

One way to deal with this was:

have another column in the table: returnId

if returnId = -1 -> one way trip else returnId = id to its complimentary itinerary

for e.g. A -> B is a roundtrip itinerary & C -> D is a one way trip;

It would look something like this:

Id    |    Departure    |    Arrival    |    ReturnId
1     |    A            |    B          |      3
2     |    C            |    D          |     -1
3     |    B            |    A          |      1

In this case pricing table

Id    |    StartDate    |    EndDate    |    Price
1     |    Jan 1, 2012  |    Dec 10,2012|      150.00
3     |    Jan 1, 2012  |    Dec 10,2012|      150.00
2     |    Jan 1, 2012  |    Dec 10,2012|      100.00

I'd like to hear thoughts/suggestions on this design ?

EDIT:

I added a related question and I think the answer to this problem will have to cater to both the requirements.

One thing, I'd like to mention is..the price for a round trip is specified as a unit and not individual components from A->B and back, B->A.

Similarly, if there are multiple segments in a trip, price is defined for the complete trip and not individual segments.


回答1:


Rather than adding a self join like that, I would have a Trip table which contains the one-to-many mapping of Trip to Itinerary (where 1 trip consists of multiple itineraries). This way, a trip can have more than 2 legs..

Something like:

Trip_Itineraries
TripId     |   ItineraryId
1          |   1
1          |   2
2          |   3

Itinerary
ItineraryId    |   Departure    |    Arrival
1              |   A            |    B      
2              |   B            |    A      
3              |   C            |    D 

Pricing
ItineraryId    |    StartDate    |    EndDate       |    Price
1              |    Jan 1, 2012  |    Jul 10,2012   |    100.00
2              |    Jul 1, 2012  |    Dec 10,2012   |    100.00
2              |    Jul 1, 2012  |    Dec 10,2012   |    150.00

Then you can do:

SELECT T.TripId, sum(P.price) 
FROM Trip_Itineraries T INNER JOIN Pricing P ON T.ItineraryId = P.ItineraryId
GROUP BY T.TripId

to get the total price for the trip..




回答2:


Blended the two answers and came up with this:

Journey:

  • journeyId
  • baggage policy
  • misc

Segment:

  • segmentId
  • journeyId (FK)
  • segment info

Price:

  • journeyId
  • startDate
  • endDate
  • price

Journey

Jid |   baggage             |   misc
1   |   "baggage policy1"   |   "round trip A->B"
2   |   "baggage policy2"   |   "one-way C->D"
3   |   "baggage policy3"   |   "one-way E->H with a hop in F, followed by G to H"

Segment

Id  |   Jid |   Dep |   Arrival
1   |   1   |   A   |   B
2   |   1   |   B   |   A
3   |   2   |   C   |   D
4   |   3   |   E   |   F
5   |   3   |   F   |   G
6   |   3   |   G   |   H

Price

JourneyId    |    StartDate    |    EndDate    |    Price
1            |    Jan 1, 2012  |    Dec 10,2012|      150.00
3            |    Jan 1, 2012  |    Dec 10,2012|      150.00
2            |    Jan 1, 2012  |    Dec 10,2012|      100.00

Thoughts ?



来源:https://stackoverflow.com/questions/9017881/how-do-i-design-return-travel-itinerary-vs-one-way-itinerary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!