首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求sql语句,查询线路,该怎么处理

2012-03-14 
求sql语句,查询线路表结构如下:SQL codeid, source_station(起点), destination_station(终点), invalid(

求sql语句,查询线路
表结构如下:

SQL code
id, source_station(起点), destination_station(终点), invalid(是否无效), timespan(用时), type(到达方式)1, '故宫',   '王府井',    0,    50, '步行' union2, '王府井', '北海',    0,    10, '地铁' union3, '北海',   '颐和园',    0,    20, '开车' union4, '颐和园', '天安门',    0,    15, '地铁' union5, '故宫',   '天安门',    0,    10, '步行' 


需要查询从A点到B点的线路?

[解决办法]
去看看邹老大的BLOG里面 有这样的一个函数。
[解决办法]
这不是统计学吗?

考研题目?
[解决办法]
--写了一个小时
SQL code
declare @source_station nvarchar(50)declare @destination_station nvarchar(50)declare @destination_station_end nvarchar(50)declare @source_station_s nvarchar(50)set @destination_station='故宫'set @destination_station_end='天安门'declare  @sql nvarchar(1000)--开始点set @sql='select * from test1 where source_station='''+@destination_station+''''--二站点select @source_station_s=source_station,@destination_station=destination_station from test1 where source_station in     (    select destination_station from test1 where source_station=@destination_station)    set @sql=@sql+' union select * from test1 where destination_station='''+@destination_station+''' and source_station='''+@source_station_s+''''begin     while(@destination_station<>@destination_station_end)    begin              select @source_station_s=source_station,@destination_station=destination_station from test1 where source_station=@destination_station        set @sql=@sql+' union select * from test1 where destination_station='''+@destination_station+''' and source_station='''+@source_station_s+''''    endendprint @sql
[解决办法]
伤不起
[解决办法]
有些事情是没有简易的方法的。
[解决办法]
一条语句比较难吧,应该用到算法,最简单就是递归

热点排行