有一个SQL语句需要优化,高手帮帮忙

fandylee828 2012-03-30 02:39:05
是分词后的查询,数据一多久很慢,这样的查询2000条数据要2秒多才能出结果,求优化,谢谢


SELECT
dbo.userlib.u_id,
dbo.Company.C_company,
DATEDIFF(day, dbo.userlib.U_regdate, GETDATE()) AS years,
dbo.userlib.U_level,
Keyword = CASE WHEN dbo.Company.c_Keyword like '本机地址'
or dbo.Company.c_Keyword like '%[,]本机地址[,]%'
or dbo.Company.c_Keyword like '%[,]本机地址'
or dbo.Company.c_Keyword like '本机地址' THEN 1
ELSE 0 END,
CASE WHEN u_level = 3 THEN 3
WHEN u_level = 2 THEN 3
WHEN u_level = 1 THEN 2
ELSE 0 END AS vip_level,
c_keyword = CASE WHEN dbo.company.c_Keyword IS NULL THEN ''''
ELSE dbo.company.c_Keyword END,
dbo.Company.c_hits,
dbo.company.c_address,
dbo.company.c_tel,
dbo.company.c_a_id,
dbo.company.c_c_id,
dbo.company.c_cy_id,
dbo.company.c_description,
c_rtime = case when dbo.company.c_RefreshTime < getdate()
or dbo.Company.c_Keyword not like '本机地址'
and dbo.Company.c_Keyword not like '%[,]本机地址[,]%'
and dbo.Company.c_Keyword not like '%[,]本机地址'
and dbo.Company.c_Keyword not like '本机地址[,]%' then '1987-08-28'
else dbo.company.c_RefreshTime end
FROM
dbo.Company INNER JOIN
dbo.userlib ON dbo.Company.C_u_id = dbo.userlib.u_id
WHERE userlib.u_yes = 1 AND c_company like '%本机地址%' or c_address like '%本机地址%' or c_tel like '%本机地址%' or c_company like '%地址%' or c_address like '%地址%' or c_tel like '%地址%' or c_company like '%本机%' or c_address like '%本机%' or c_tel like '%本机%' or c_company like '%地%' or c_address like '%地%' or c_tel like '%地%' or c_company like '%址%' or c_address like '%址%' or c_tel like '%址%' or c_company like '%本%' or c_address like '%本%' or c_tel like '%本%' or c_company like '%机%' or c_address like '%机%' or c_tel like '%机%' or c_keyword like '本机地址' or c_keyword like '%[,]本机地址[,]%' or c_keyword like '%[,]本机地址' or c_keyword like '本机地址[,]%'
...全文
81 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
shshjun 2012-03-30
建议引入视图,然后从视图中查询.视图是预编译的,能好一点.
回复
唐诗三百首 2012-03-30
模糊查询,不好优化耶.
回复
SQL777 2012-03-30
都一些LIKE 语句没啥好办法。全文索引吧

你AND 与OR的地方都不打括号的?
回复
dawugui 2012-03-30
你这么多or条件,基本上使用的是like,快不起来的.
回复
相关推荐
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2012-03-30 02:39
社区公告
暂无公告