| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1151 人关注过本帖
标题:关于公交查询的算法~~希望大家有时间帮忙指点一二啊!!!
只看楼主 加入收藏
v123981499
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-5-18
收藏
 问题点数:0 回复次数:4 
关于公交查询的算法~~希望大家有时间帮忙指点一二啊!!!
这是关于中转站换乘的一个存储过程,在执行查询的时候,直达路线可显示,但换乘就没有显示了(即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
makebest
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:3
帖 子:658
专家分:962
注 册:2005-3-17
收藏
得分:0 
换乘一次的查询语句
select b1.StationName,b1.LineID,b2.StationName,B3.LineID,b4.StationName
from 线路表 as b1,
线路表 as b2,
线路表 as b3,
线路表 as b4
where b1.StationName=@BeginStation
and b1.LineID = b2.LineID
and b2.StationName = b3.StationName and b2.LineID<>b3.LineID
and b3.LineID = b4.LineID
and b4.StationName = @EndStation
2008-06-14 20:13
球球
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:1146
专家分:265
注 册:2005-11-28
收藏
得分:0 
create proc proc_train
@startaddress varchar(5),
@endaddress varchar(5)
as
select s.schedulecode,s.cityname into #ttb1 from (select * from T_schedule_detail where schedulecode in
(select schedulecode from T_schedule_detail where cityname=@startaddress)) s,
(select * from T_schedule_detail where schedulecode in
(select schedulecode from T_schedule_detail  where cityname=@endaddress )) e where s.cityname=e.cityname

select A.schedulecode,A.fromcity,A.tocity,A.leavetime,A.arrivaltime,A.traintype,A.speed ,A.distance,A.days,B.cityname into #ttb2 from T_schedule A,ttb1 B where A.schedulecode=B.schedulecode

select A.schedulecode,A.fromcity,A.tocity,A.leavetime,A.arrivaltime,A.traintype,A.speed ,A.distance,A.days,B.cityname into #ttb_line_midway from ttb1 B,ttb2 A where A.schedulecode=B.schedulecode
go

好累
2008-06-15 09:27
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.019091 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved