日期:2014-05-18  浏览次数:20405 次

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