| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 885 人关注过本帖
标题:怎样做一个公交线路查询系统
收藏  订阅  推荐  打印 
fanny_6
Rank: 1
等级:新手上路
帖子:3
积分:130
注册:2006-2-15
怎样做一个公交线路查询系统

最近要做一个模型类似公交查询系统的,但是我没有接触过数据库
公交车数据表
Num     Station1     Station2     Station3     Station4    Station5 ....
1      火车站     五里牌     晓园路口     袁家岭    清水塘 ....
2      火车站     火车南站    汽车南站     袁家岭    植物园 ....
.
. 输入:车站
输出: 1路车    
   2路车  
 
输入:1路车
输出: 1 火车站 五里牌 晓园路口 袁家岭 清水塘 ....


但这才5个字段,如果有10多个站,多的20多个站,像我这种查询方法是不科学的!怎样改进?

如果有这方面的资料,也麻烦链接一个,万分感谢
搜索更多相关主题的帖子: 公交线路  DIV  数据库  系统  袁家岭  
2006-2-15 16:09
wsn
Rank: 3Rank: 3
等级:中级会员
威望:5
帖子:324
积分:3390
注册:2006-2-9

我觉得你把结构改成只有两个列就简单了,station列用火车站|五里牌|....来表未,或外加一张表专门用于存车站名,在上面的表中只放车站编码就好处理了

已婚男人!没事请勿打扰·老婆格言:①不准對她耍酷 ②不准讓她吃醋 ③吵架我要讓步 ④揍我我要挺住⊙⊙
2006-2-16 09:21
houjunli
Rank: 3Rank: 3
等级:中级会员
威望:5
帖子:343
积分:3530
注册:2006-2-16

不在与站多站少。主要是看你的查询系统要怎么查询,就要在系统里怎么处理


2006-2-16 15:40
marydan
Rank: 2
等级:注册会员
帖子:54
积分:790
注册:2006-2-14

1)stop_info(站牌信息表)

列名

类型

缺省值

说明

Stop_No

int

0

站牌编号

Stop_name

Varchar(20)

null

站牌名称

主键(Stop_No)

2)path_info(公交路线信息)

列名

类型

缺省值

说明

Bus_No

int

0

公交编号

Stop_No

int

0

站牌编号

Order_No

int

0

站牌次序

Time_differ

int

0

与前站相隔时间,单位是分钟

主键:(Bus_No,Stop_No)外键(Stop_No)


create table stop_info (stop_no int default 0 ,

stop_name varchar(20) null,

primary key(stop_no) )

create table path_info (bus_no int default 0,

stop_no varchar(20) default 0,

order_no int default 0 ,

time_differ int default 0,

primary key(bus_no,stop_no),

foreign key(stop_no) references stop_info(stop_no) )

我的眼里只有你
2006-2-17 16:03
marydan
Rank: 2
等级:注册会员
帖子:54
积分:790
注册:2006-2-14


/*查询某公车线路*/
select a.order_no,b.stop_name
from path_info a,stop_info b
where a.stop_no=b.stop_no
and a.bus_no=253/*此处仅为举例,写程序时可作为形参传入*/
order by a.order_no



我的眼里只有你
2006-2-17 16:11
marydan
Rank: 2
等级:注册会员
帖子:54
积分:790
注册:2006-2-14

/*查询可经过指定起始地的公车*/
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编辑过]


我的眼里只有你
2006-2-17 16:17
marydan
Rank: 2
等级:注册会员
帖子:54
积分:790
注册:2006-2-14

drop #tempinf14
drop #tempinf13


这个其实不大完整,很不好,但是我目前只能想到这些,希望能抛砖引玉,多学习别人:)

缺点:1、又臭又长,非常不好
2、我只考虑了单向,呵呵,就是 从A-B可以查,从B-A回来的,我不知道怎么做

优点:没有复杂语句,谁看谁懂



我的眼里只有你
2006-2-17 16:25
marydan
Rank: 2
等级:注册会员
帖子:54
积分:790
注册:2006-2-14

请大家多多指正:)
各位前辈多多指导:)

我的眼里只有你
2006-2-17 16:27
fanny_6
Rank: 1
等级:新手上路
帖子:3
积分:130
注册:2006-2-15

谢谢各位的热心帮助,启发不少
2006-2-20 10:21
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

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