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

查询有关问题,路过看下

2012-04-06 
查询问题,路过看下。表A区域地址-------------------------普陀区镇坪路176弄普陀区镇坪路177弄普陀区镇坪

查询问题,路过看下。
表A
区域               地址                  
-------------------------  
普陀区             镇坪路176弄          
普陀区             镇坪路177弄    
普陀区             镇坪路180弄      
普陀区             镇坪路181弄
普陀区             曹杨路22弄

我想根据我输入的   地址取最接近的三个。

  如:输入   镇坪路176弄
出来::
区域               地址                  
-------------------------  
普陀区             镇坪路176弄          
普陀区             镇坪路177弄    
普陀区             镇坪路180弄  


[解决办法]
太难了,不会

[解决办法]
这么智能化的东西SQL做不了吧.
[解决办法]
地址 里面怎么样知道是最近的呢?
[解决办法]
是啊,要是输入的是:曹杨路22弄
这里面就一个曹杨路怎么判断最近啊
[解决办法]
declare @test table (区域 varchar(50), 地址 varchar(50))
insert @test
select '普陀区 ', '镇坪路176弄 '
union all select '普陀区 ', '镇坪路177弄 '
union all select '普陀区 ', '镇坪路180弄 '
union all select '普陀区 ', '镇坪路181弄 '
union all select '普陀区 ', '曹杨路22弄 '
select 区域, 地址 from @test a where 地址 in (select top 3 地址 from @test where 地址 like '曹杨路__弄 ' and 地址 > = '曹杨路22弄 ' and 区域 = a.区域) order by 区域, 地址
select 区域, 地址 from @test a where 地址 in (select top 3 地址 from @test where 地址 like '镇坪路___弄 ' and 地址 > = '镇坪路176弄 ' and 区域 = a.区域) order by 区域, 地址
select 区域, 地址 from @test a where 地址 in (select top 3 地址 from @test where 地址 like '镇坪路___弄 ' and 地址 > = '镇坪路177弄 ' and 区域 = a.区域) order by 区域, 地址
select 区域, 地址 from @test a where 地址 in (select top 3 地址 from @test where 地址 like '镇坪路___弄 ' and 地址 > = '镇坪路181弄 ' and 区域 = a.区域) order by 区域, 地址

[解决办法]
弄出来,学一招!

热点排行