换乘问题的数据库设计
线路,站点,次序
所有车次:select distinct 线路 from bus
某条线路:select 站点 from bus where 线路==x order by 次序
直达:select x.*, y.* from bus x, bus y where x.线路 == y.线路 and x.次序 < y.次序 and x.站点 == s and y.站点 == e
一次换乘:视图,自连接,所有直达
线路a,站点a,次序a,线路b,站点b,次序b(次序递增)
select viewa.站点s,viewa.线路s,viewa.站点e,viewa.线路e, viewb.站点s,viewb.线路s,viewb.站点e,viewb.线路e from
vview viewa, vview viewb where{
viewa.站点b == viewb.站点a and
viewa.站点a == s and
viewb.站点b == e
}
已经包含中转站信息
二次更多次换乘:视图,继续连接,保留中转站信息,个人感觉做到四次换乘就行了,超过四次就打的吧。
比较困难的地方在打印出完整的换乘信息,但是没有技术难度,只是有些复杂。