| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付买域名,送MP3、MP4
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY买空间,免费送域名(厦门中资源)
共有 547 人关注过本帖
标题:关于公交查询的算法~~希望大家有时间帮忙指点一二啊!!!
收藏  订阅  推荐  打印 
v123981499
Rank: 1
等级:新手上路
帖子:12
积分:226
注册:2008-5-18
关于公交查询的算法~~希望大家有时间帮忙指点一二啊!!!

这是关于中转站换乘的一个存储过程,在执行查询的时候,直达路线可显示,但换乘就没有显示了(即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-6-4 21:23
v123981499
Rank: 1
等级:新手上路
帖子:12
积分:226
注册:2008-5-18

有没有人帮帮我啊!!!!
2008-6-14 13:04
makebest
Rank: 3Rank: 3
等级:中级会员
帖子:387
积分:4140
注册:2005-3-17
换乘一次的查询语句

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-6-14 20:13
球球
Rank: 12Rank: 12Rank: 12
等级:版主
威望:18
帖子:938
积分:9523
注册:2005-11-28

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-6-15 09:27
v123981499
Rank: 1
等级:新手上路
帖子:12
积分:226
注册:2008-5-18

谢谢 3楼的 ,虽然 4楼的似乎比较好,但是以本人目前的知识结构理解起来还是有点困难的,所以采用了3楼,呵呵
2008-6-15 17:44
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.064320 second(s), 10 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved