/*查询可经过指定起始地的公车*/
declare @stop_no1 int ,
@stop_no2 int ,
@bus_no int ,
@order_no1 int ,
@order_no2 int
select @stop_no1=stop_no
from stop_info
where stop_name='火车站'/*此处仅为举例,写程序时可作为形参传入*/
select @stop_no2=stop_no
from stop_info
where stop_name='邮电大楼'
declare @cout11 int,
@cout22 int
create table #tempinf13(no2 int)
insert into #tempinf13
select bus_no
from path_info
where stop_no =@stop_no1
select @cout11=@@rowcount
create table #tempinf14(no2 int)
insert into #tempinf14
select bus_no
from path_info
where stop_no =@stop_no2
select @cout22=@@rowcount
if(@cout11>=@cout22)
begin
select @bus_no=a.no2
from #tempinf13 a,#tempinf14 b
where a.no2=b.no2
end
else
begin
select @bus_no=b.no2
from #tempinf13 a,#tempinf14 b
where a.no2=b.no2
end
print @bus_no
/*求中间站*/
select @order_no1=order_no
from path_info
where stop_no= @stop_no1
select @order_no2=order_no
from path_info
where stop_no=@stop_no2
declare @max_no int,
@min_no int
select @max_no=0,
@min_no=0
if(@order_no1>@order_no2)
begin
select @min_no=@order_no2
select @max_no=@order_no1
end
else
begin
select @min_no=@order_no1
select @max_no=@order_no2
end
select a.stop_name
from path_info b,bus_info a
where b.bus_no=@bus_no
and b.order_no<=@max_no
and b.order_no>=@min_no
and b.stop_no=a.stop_no
/*求所需时间*/
select sum(time_differ) as '共需时间'
from path_info b
where b.bus_no=@bus_no
and b.order_no<=@max_no
and b.order_no>=@min_no
[此贴子已经被作者于2006-2-17 16:19:23编辑过]