select * from Count where 
charindex('baidu.com',CountReferer)>0 or  charindex('google',CountReferer)>0 or 
charindex('yahoo',CountReferer)>0 or  charindex('yahoo.com',CountReferer)>0 
or  charindex('sogou.com',CountReferer)>0 or  charindex('tom.com',CountReferer)>0
or  charindex('163.com',CountReferer)>0 or  charindex('soso.com',CountReferer)>0 
or  charindex('iask.com',CountReferer)>0 or  charindex('msn.com',CountReferer)>0---------------
这样好像要全表搜索,怎么写才能更好,谢谢!

解决方案 »

  1.   

    好像也只能这么写了。或者用LIKE
      

  2.   

    在CountReferer上建索引.charindex('yahoo',CountReferer)>0 or  charindex('yahoo.com',CountReferer)>0 
    这两个条件重复
      

  3.   

    去掉charindex('yahoo.com',CountReferer)>0
      

  4.   


    CharIndex 和 LIke '%关键字%' 两者效率差不多,都使用不上索引。用全文索引试试。
      

  5.   

    select * from (
    select * from Count where charindex('baidu.com',CountReferer)>0 union all
    select * from Count where charindex('google',CountReferer)>0 union all
    select * from Count where charindex('yahoo',CountReferer)>0  union all
    select * from Count where charindex('yahoo.com',CountReferer)>0  union all
    select * from Count where charindex('sogou.com',CountReferer)>0  union all
    select * from Count where charindex('tom.com',CountReferer)>0  union all
    select * from Count where charindex('163.com',CountReferer)>0  union all
    select * from Count where charindex('soso.com',CountReferer)>0  union all
    select * from Count where charindex('iask.com',CountReferer)>0  union all
    select * from Count where charindex('msn.com',CountReferer)>0 ) t
      

  6.   

    charindex和LIKE没有什么区别
    这个查询没有救了其实如果有这个需要,建表时应该把这个规划出来的
      

  7.   

    varchar类型可以建立索引吗!!有效吗~
      

  8.   

    添加一个siteId字段,可以在你查询前维护其值或插入数据时。如:
    id,site
    1,google.com
    2,baidu.com
    4,sohu.com
    8,yahoo.com查询google+baidu+yahoo的语句就是:
    select * from table where siteId & (1+2+8) = siteId
    位运算,速度超快~~~
      

  9.   


    CharIndex 和 LIke '%关键字%' 两者效率差不多,都使用不上索引。而 LIke '关键字%',可以使用索引。用全文索引试试。
      

  10.   

    用全文索引CONTAINSTABLE:
    SELECT K.RANK, CompanyName, ContactName, Address
    FROM Customers AS C
         INNER JOIN
         CONTAINSTABLE(Customers,Address, 'ISABOUT ("des*",    
                                                    Rue WEIGHT(0.5), 
                                                    Bouchers WEIGHT(0.9)
                                                   )
                                          ' 
                      ) AS K
         ON C.CustomerID = K.[KEY]
      

  11.   

    鼹鼠的语句感觉应该是这样吧,
    select * from table where siteId & (1+2+8)<>0
    方法不错,速度快,缺点是不能有太多的数据,指数的增长速度很快的,呵呵
      

  12.   

    hyc_music1981(穿裤衩的地狱天使) select * from table where siteId & (1+2+8) = siteId

    select * from table where siteId & (1+2+8)<>0
    没有什么大区别,因为值不是0就是siteId
      

  13.   

    只是站点的类型不能太多,
    int 类型可以有32种类型,bigint 可以有64种类型。
      

  14.   

    int有三十一种,bigint有六十三种,呵呵
      

  15.   

    hyc_music1981(穿裤衩的地狱天使) ( ) 信誉:100    Blog   加为好友  2007-04-17 16:11:33  得分: 0  
     
     
       int有三十一种,bigint有六十三种,呵呵
      
     
    赞同:)
      

  16.   

    to CrazyFor(冬眠的鼹鼠):
    不是很懂~~能详细点告诉吗!
      

  17.   

    鼹鼠的意思是你加一列,对应赋以下值:
    id,CountReferer 
    1,google.com
    2,baidu.com
    4,sohu.com
    8,yahoo.com
    然后你查包含哪些网站的信息,就把哪些id加起来,比如找包含baidu,google,yahoo的就是8+2+1,使用select * from count where id & (1+2+8) = id
    "&"的意思是逻辑与,而1,2,4,8 ...正对应了二进制的每一位1+2+8二进制就是1011,如果你的CountReferer 是baidu,id是2(0010)那么与的结果就是0010,如果是sohu,id是4(0100)与的结果就是0000
      

  18.   

    charIndex和left没有区别??别扯了...
    我原来做了个查询,数据量很大,用charIndex简直语句没办法运行
      

  19.   

    还有解决办法就是如果楼主的数据库是SQL2005的话,可以使用C#编写存储过程。毕竟,取数据集合操作是SQL的强项,而逻辑操作则是程序的强项