本文介绍了sql查询工作非常缓慢.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

专家,

有2个表emailinfo(id,email)和keywordinfo(id,keyword).
emailinfo包含80,000行,而keywordinfo包含2000行.


我想要来自emailinfo表的电子邮件,其中不包含来自keywordinfo表的关键字.

我的查询如下所示.

Hi Expert,

There 2 tables emailinfo(id,email) and keywordinfo(id,keyword).
emailinfo contains 80,000 rows and keywordinfo contains 2000 rows.


I want emails from emailinfo table which does not contains keywords from keywordinfo table.

And my query is like following.

SELECT  EMAIL.email FROM emailinfo EMAIL    WHERE   (  not exists( Select keyword from keywordinfo where EMAIL.email  like '%'+ keyword +'%' ))




但是执行需要3分钟.

请帮助我解决这个问题.

在此先谢谢您.




but it takes 3 minutes to execute .

please help me to slove this problem.

Thanks in advance.

推荐答案

SELECT  [email]
FROM emailinfo
WHERE NOT [email] IN(SELECT [keyword] AS [email]
                    FROM keywordinfo
                    WHERE [keyword] like '%'+ keyword +'%' )


WITH keywords AS
(
  SELECT
    keyword
  FROM
    keywordinfo
)

SELECT
  emailinfo.email
FROM
  emailinfo
WHERE
  emailinfo.email NOT LIKE '%' + keywords.keyword + '%'



这篇关于sql查询工作非常缓慢.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 23:21