有一个IP地址对应物理地址的表,IP分为startIP和EndIP 两部分,加密了的
例如:startIP EndIP Country
61.55.164.55 61.55.164.81 aa市网通ADSL
61.55.164.82 61.55.164.82 bb市XX网吧
61.55.164.83 61.55.164.101 cc市yy区ADSL
... 但在查询过程中遇到问题:例如我在查询'218.18.159.177' 这个IP是属于什么地区的,如果用
select * from tableIP
where '218.18.159.177' Between 起始IP and 结束IP搜索结果:
202.18.15.0 202.18.16.255 xx电信ADSL
202.18.158.0 202.18.167.255 yy市
202.176.0.0 202.183.255.255 CZ88.NET 实际上,我需要的是 202.18.158.0 202.18.167.255 yy市 这条记录.还需继续筛选.有没有更好的查询方法?
例如:startIP EndIP Country
61.55.164.55 61.55.164.81 aa市网通ADSL
61.55.164.82 61.55.164.82 bb市XX网吧
61.55.164.83 61.55.164.101 cc市yy区ADSL
... 但在查询过程中遇到问题:例如我在查询'218.18.159.177' 这个IP是属于什么地区的,如果用
select * from tableIP
where '218.18.159.177' Between 起始IP and 结束IP搜索结果:
202.18.15.0 202.18.16.255 xx电信ADSL
202.18.158.0 202.18.167.255 yy市
202.176.0.0 202.183.255.255 CZ88.NET 实际上,我需要的是 202.18.158.0 202.18.167.255 yy市 这条记录.还需继续筛选.有没有更好的查询方法?
解决方案 »
- Direct3D中如何计算所求阴影的面积(主要是不知怎么获取阴影的顶点的坐标)
- 为什么用IE就可以登录,用FF还有Opera就提示错误>_<
- DataSet 條件查詢問題 或DataView分頁問題
- C# 读取xml文件显示到datagridview
- Microsoft.JScript.Eval.JScriptEvaluate 这个函数支持函数吗?
- 如何替换文本中的16进制字符!
- 召集C语言程序高手~急~
- pb到c#
- CString的Left函数的功能用string如何实现?
- 问题两则,在线等待!
- 用sql怎么都行,今天用access(2003)结果发现怎么都报错,请大家帮忙
- using System.Web.Mail;在编译时出错啊
where '218.18.159.177' Between 起始IP and 结束IP 改为:select * from tableIP
where '218.18.159.177' Between startIP and EndIP
where '218.18.159.177' Between startIP and EndIP
-----------------
这就行了
where left(startIP,len('218.18.159.'))=left('218.18.159.177',len('218.18.159.')) and left(EndIP,len('218.18.159.'))=left('218.18.159.177',len('218.18.159.'))
and cast(right(startIP,len('177')) as int)<=177
and cast(right(EndIP,len('177')) as int)>=177
union
select * from tableIP
where left(startIP,len('218.18.'))=left('218.18.159.177',len('218.18.')) and left(EndIP,len('218.18.'))=left('218.18.159.177',len('218.18.'))
and cast(
SUBSTRING(startIP,len('218.18.')+1,len(startIP)-len('218.18.')-1)
as decimal(18,3))<=159
and cast(
SUBSTRING(EndIP,len('218.18.')+1,len(EndIP)-len('218.18.')-1)
as decimal(18,3))>=159