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---------------
这样好像要全表搜索,怎么写才能更好,谢谢!
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---------------
这样好像要全表搜索,怎么写才能更好,谢谢!
这两个条件重复
CharIndex 和 LIke '%关键字%' 两者效率差不多,都使用不上索引。用全文索引试试。
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
这个查询没有救了其实如果有这个需要,建表时应该把这个规划出来的
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
位运算,速度超快~~~
CharIndex 和 LIke '%关键字%' 两者效率差不多,都使用不上索引。而 LIke '关键字%',可以使用索引。用全文索引试试。
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]
select * from table where siteId & (1+2+8)<>0
方法不错,速度快,缺点是不能有太多的数据,指数的增长速度很快的,呵呵
和
select * from table where siteId & (1+2+8)<>0
没有什么大区别,因为值不是0就是siteId
int 类型可以有32种类型,bigint 可以有64种类型。
int有三十一种,bigint有六十三种,呵呵
赞同:)
不是很懂~~能详细点告诉吗!
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
我原来做了个查询,数据量很大,用charIndex简直语句没办法运行