| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1155 人关注过本帖
标题:关于公交查询的算法~~希望大家有时间帮忙指点一二啊!!!
取消只看楼主 加入收藏
v123981499
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-5-18
收藏
 问题点数:0 回复次数:2 
关于公交查询的算法~~希望大家有时间帮忙指点一二啊!!!
这是关于中转站换乘的一个存储过程,在执行查询的时候,直达路线可显示,但换乘就没有显示了(即else后的语句),貌似也没有什么语法错误。第一个if是起点和终点在一条线路上的,else是关于中转站的查找及换车的路线。其中,lineid为线路的名称,stationname为站点的名称,希望大家可以帮帮我,找出其中的错误和不足之处,小妹在此感激不尽!!! ( 可QQ联系:123981499,请注明来意,谢谢!)

CREATE procedure s_to_s_select
(  
 @BeginStation varchar(20),
 @EndStation   varchar(20)
)
as
if exists     
 (     
        select *                   --起点和终点在同一条线路上
        from 线路表 as a
        where StationName=@BeginStation   
        and      
        StationName in                        
                            (
                                select StationName           
                                 from 线路表  as b
                                  where StationName=@EndStation   
                                   and  a.LineID=b.LineID
       )
  )      
                           
     select *                   --起点和终点在同一条线路上
        from 线路表 as a
        where StationName=@BeginStation
        and      
        StationName in                        
                            (
                                select StationName           
                                 from 线路表  as b
                                  where StationName=@EndStation   
                                   and  a.LineID=b.LineID
       )   order by Turn
   
else   
      if exists               --经过两站的不同线路中有交点
     (  select *                       
        from 线路表 as a
        where stationname in (                --经过起点的线路上的所有点
                                           select stationname
                                           from 线路表 as b
                                           where lineid in (
                                                                    select lineid
                                                                     from 线路表 as c
                                                                      where stationname like rtrim (@BeginStation)
                                                                  )
                                           )
       and      
                  stationname in (                        --过终点
                                           select stationname
                                           from 线路表 as b
                                           where lineid in (
                                                                    select lineid
                                                                     from 线路表 as c
                                                                      where stationname like rtrim (@EndStation)
                                                                  )
                                           )
                  )
        select *                       --查找线路
        from 线路表 as a
        where stationname in (
                                           select stationname
                                           from 线路表  as b
                                           where lineid in (
                                                                    select lineid
                                                                     from 线路表 as c
                                                                      where stationname like rtrim (@BeginStation)
                                                                  )
                                           )
       and     
                  stationname in (
                                           select stationname
                                           from 线路表 as b
                                           where lineid in (
                                                                    select lineid
                                                                     from 线路表 as c
                                                                      where stationname  like rtrim (@EndStation)
                                                                  )  
                                           )
        and     lineid in (
                            select lineid
                            from 线路表  as b
                             where stationname like rtrim (@BeginStation)                          
                           )
        and     lineid in (
                            select lineid
                            from 线路表  as b
                             where stationname like rtrim (@EndStation)           
                           )
       order by turn
GO
搜索更多相关主题的帖子: 算法 公交 中转站 线路 else 
2008-06-04 21:23
v123981499
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-5-18
收藏
得分:0 
有没有人帮帮我啊!!!!
2008-06-14 13:04
v123981499
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-5-18
收藏
得分:0 
谢谢 3楼的 ,虽然 4楼的似乎比较好,但是以本人目前的知识结构理解起来还是有点困难的,所以采用了3楼,呵呵
2008-06-15 17:44
快速回复:关于公交查询的算法~~希望大家有时间帮忙指点一二啊!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017889 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved