我的查询语句如下select * from T_Wish w inner join T_ip i on w.iplong>i.ip1 and w.iplong<i.ip2 where 1=1 order by ID desc我的ip地址库如下形式
ip1                  ip2                  Country                                            city                                                                                                                                                                                                     
-------------------- -------------------- -------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
0                    16777215             IANA                                               CZ88.NET
16777216             33554431             IANA                                               CZ88.NET
33554432             50331647             IANA                                               CZ88.NET
50331648             67108863             美国                                                 新泽西通用电气公司
67108864             67829759             美国                                                 CZ88.NET
67829760             67895295             美国                                                 夏威夷
67895296             68374015             美国                                                 CZ88.NET
68374016             68374271             美国                                                 西南政法大学
68374272             68374335             美国                                                 Armed Forces Radio/Television
68374336             68530431             美国                                                 CZ88.NET

解决方案 »

  1.   

    T_Wish 的结构怎么样的?怎么语句里有where 1=1 什么意思?
      

  2.   

    T_Wish结构类似id          nickname                                           username                                           message                                                                                                                                                                                                  posttime                                               ip              colorid faceid iplong               show ip1                  ip2                  Country                                            city                                                                                                                                                                                                     
    ----------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------ --------------- ------- ------ -------------------- ---- -------------------- -------------------- -------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
    134         欢欢                                                 杂志读者                                               希望爸爸身体早日康复,弟弟旧病不会复发,我和他工作顺利,妈妈身体健康,全家都要开开心心的!~~                                                                                                                                                          2007-04-29 09:51:34.077                                64.104.168.165  7       3      1080600741           1    1080295424           1080623103           美国                                                 思科公司
    132         路人                                                 杂志读者                                               世界和平,所有生灵都快乐的生活                                                                                                                                                                                          2007-04-29 09:21:20.187                                221.219.181.68  3       2      3722163524           1    3722163200           3722165247           北京市丰台区                                             网通
      

  3.   

    错了,上面是
    select * from T_Wish w inner join T_ip i on w.iplong>i.ip1 and w.iplong<i.ip2 where 1=1 order by ID desc的结果T_Wish的结果如下
    id          nickname                                           username                                           message                                                                                                                                                                                                  posttime                                               ip              colorid faceid iplong               show 
    ----------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------ --------------- ------- ------ -------------------- ---- 
    135         lee                                                杂志读者                                               愿我的susan能在新的生活里一切如愿。新的生活,心的生活,也愿我跟她的心有我们的生活。                                                                                                                                                             2007-04-29 10:28:21.780                                61.187.179.67   5       3      1035711299           1
    134         欢欢                                                 杂志读者                                               希望爸爸身体早日康复,弟弟旧病不会复发,我和他工作顺利,妈妈身体健康,全家都要开开心心的!~~                                                                                                                                                          2007-04-29 09:51:34.077                                64.104.168.165  7       3      1080600741           1
      

  4.   

    ip导入sqlserver数据库
    1.下载QQ纯真ip数据库.
    2.执行ShowIP.exe,数据解压至ip.txt中
    3.打开ip.txt,替换所有空格为"|"
    4.对于表中只有国家没有城市的记录,补齐城市的名称方法为
    替换文本5|CZ88.NET为5|CZ88.NET|CZ88.NET
    4.在数据库中建临时ip表iptable,字段为
    Startip varchar(50)--起始ip
    Endip   varchar(50)--终止ip
    country varchar(50)--国家
    city    varchar(50)--城市
    5.在sqlserver查询中执行EXEC master..xp_cmdshell 'bcp test.dbo.testtable in e:\ip.txt -c -q  -U "sa" -P "pwd" -t"|"' 将数据导入表中
    6.此时如需要分离省份与具体城市,建立二字段
    s_province varchar(50)--存储省份名称
    city2      varchar(50)--存储城市名称
    7.在查询分析器中执行语句
    update iptable set city2=right(Country,len(Country)-charindex('省',Country)),s_province=left(Country,charindex('省',Country)) where charindex('省',Country)>0
    更新新的省份及城市ip字段
    8.计算ip为256位数字.
    (1)建字段 stipcompute decimal,edipcompute decimal
    (2)在sqlserver中准备函数
    CREATE FUNCTION [dbo].[FunCmpIp] (@startip varchar(40))
    RETURNS decimal
    AS
    BEGIN
    declare @i int   --标记ip地址中的"."符号位置
    declare @pw int  --2进制的幂值
    declare @ipvalue decimal--计算ip的二进制值
    set @ipvalue=0
    set @pw=3
    --set @startip='192.168.0.1'
    set @i=charindex('.',@startip)
    while @i>=1
    begin
    --insert @temp values(replace(left(@startip,@i-1),' ',''))
    set @ipvalue=@ipvalue+CAST(replace(left(@startip,@i-1),' ','') as decimal)*POWER(256,@pw)
    set @startip=substring(@startip,@i+1,len(@startip)-@i)
    set @i=charindex('.',@startip)
    set @pw=@pw-1
    end
    set @ipvalue=@ipvalue+CAST(@startip as int)
    return @ipvalue
    END;
    (3)
    EXEC master..xp_cmdshell 'bcp "select Startip,Endip,s_province,city2,stipcompute,edipcompute from callbook_dw.dbo.iptable1" queryout e:\yao.txt -c -U"sa" -P"pwd" -t","'
      

  5.   

    这是我原来写的东西,索引那块没写里面,索引建到decimal的列上就可以了。
      

  6.   

    在经常用于连接的列(这些列主要是一些外键)上创建索引
    在经常需要根据范围进行搜索的列上创建索引,因为索引已经排序,其指定的范围是连续的;
    在经常需要排序的列上创建索引,因为索引已经排序,这样查询可以利用索引的排序
    在经常使用于WHERE子句中的列上创建索引,加快条件的判断速度。
    感觉这里的话就是在iplong 和ip1 ,ip2上建立索引
      

  7.   

    ip1和ip2是分别建索引还是联合建索引。
    iplong也要建吗?我的查询语句用w.iplong>i.ip1 and w.iplong<i.ip2 
    和用w.iplong between i.ip1 and i.ip2有区别吗?
      

  8.   

    我在ip1和ip2上分别建立了索引,其中Ip1是聚集索引,两个索引都是升序,结果查询效率增加了一倍多。原来10秒,11秒的查询,现在只用4,5秒。
      

  9.   

    经过我测试
    查询语句用w.iplong>i.ip1 and w.iplong<i.ip2 
    和用w.iplong between i.ip1 and i.ip2
    没有区别
      

  10.   

    我也觉得应该ip1-2分别建索引
    iplong上建了么,试试看,我也很想知道结果:)
      

  11.   

    测试结果
    Iplong上建索引没有效果
    另外有个特别特别特别奇怪的现象:
    当我没有建ip1和ip2的索引之前
    p_splitPage_XiaoZhengGe 'select top 30 * from T_Wish w inner join T_ip i on w.iplong>i.ip1 and w.iplong<i.ip2 where 1=1 order by ID desc',1,30
    明显快于
    p_splitPage_XiaoZhengGe 'select * from T_Wish w inner join T_ip i on w.iplong>i.ip1 and w.iplong<i.ip2 where 1=1 order by ID desc',1,30但是当我建立了索引之后,反而第一个语句比第二个语句还慢。
      

  12.   

    1、执行存储过程返回的表怎么取得呢。我想和这个表进行inner join操作2、当返回多个表的时候怎么办呢。我怎么从中找到我需要的表呢。
    比如
    p_splitPage_XiaoZhengGe 'select top 10 * from T_Wish',1,30
    返回3个表。我想取得其中的第三个表,然后在和T_ip表进行inner join
      

  13.   

    ORDER BY 要和索引列相对应才能发挥索引的效果
      

  14.   

    直接读取qqwry.dat比较好,性能高,另外,数据比较权威
      

  15.   

    再顶
    1、执行存储过程返回的表怎么取得呢。我想和这个表进行inner join操作2、当返回多个表的时候怎么办呢。我怎么从中找到我需要的表呢。
    比如
    p_splitPage_XiaoZhengGe 'select top 10 * from T_Wish',1,30
    返回3个表。我想取得其中的第三个表,然后在和T_ip表进行inner join
      

  16.   

    将IP转化为整数存储,写自己的数据系统,有三种实现方式:
    1.用树结构应该是最快的
    2.将iP进行倒排索引
    3.将IP排序好,每次查询的时候都进行二分或插值查找,这种效率最低,但用的空间也是最少的