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

IP地址查询 急解决方案

2012-03-21 
IP地址查询 急啊表A中有列IP保存的是ip地址格式如下IP198.168.0.1192.168.0.5192.168.0.15192.168.0.21519

IP地址查询 急啊
表A中   有列   IP   保存的是ip地址   格式如下  
IP
198.168.0.1
192.168.0.5
192.168.0.15
192.168.0.215
192.168.1.5
192.168.1.25
192.168.1.23
192.168.1.155
192.168.2.5
192.168.2.53
192.168.2.223
//////////
请问我想查询某个IP段之间(如192.168.0.1-192.168.0.255   是一个IP段   而   198.168.1.1-192.168.1.255   是另一个IP段)都有那些IP怎么写SQL语句?

假若我要查询   192.168.0.1-192.168.0.255   这个IP断那么就应该市
IP
198.168.0.1
192.168.0.5
192.168.0.15
192.168.0.215

[解决办法]
select * from A
where ip like '192.168.0.% '
[解决办法]
加个条件不就行了呀

create table A(ip varchar(20))
insert A select '198.168.0.1 '
union all select '192.168.0.5 '
union all select '192.168.0.15 '
union all select '192.168.0.215 '
union all select '192.168.1.5 '
union all select '192.168.1.25 '
union all select '192.168.1.23 '
union all select '192.168.1.155 '
union all select '192.168.2.5 '
union all select '192.168.2.53 '
union all select '192.168.2.223 '

select * from A
where ip like '192.168.0.% '
and cast(substring(ip,11,3) as tinyint) between 56 and 255

热点排行
Bad Request.