2015-02-05 31 views
0

我使用的MySQL,我那里有所谓的公司,办公,电子邮件,国家和评级MySQL查询获取不同的数据比预期

我不希望有域AOL,Gmail,Google云端电子邮件列的表mtn_extract_list_email

我使用的查询是

select email from mtn_extract_list_email where (company like '%XYZ%' or office like '%XYZ%') 
and (email not like '%@aol%' or email not like '%@gmail%' or email not like '%@google%') 
and (Country = 'USA' and rating like 'A%') 
and email is not null; 

此查询获取数据,但我注意到,它也进账电子邮件@gmail为域名。我尝试调整“AND”和“或”逻辑,但仍然没有运气。请指导我的查询有什么问题。

+1

请将您的问题标题描述为描述您遇到的实际问题的内容。 *查询无法正常工作如果*对于本网站的未来用户的搜索结果显示为“*”,那么它将毫无意义。你的头衔实际上应该是描述性的;很明显你的查询不能按你的意愿工作,或者你不会在这里发布问题。 – 2015-02-05 23:18:02

+1

你不想在AOL域名,你不想要Gmail,而你不想谷歌。问题是你的查询使用'OR'。 – LSerni 2015-02-05 23:19:17

+0

(电子邮件不像'%@ aol%'和电子邮件不像'%@ gmail%'和电子邮件不像'%@ google%') – 2015-02-05 23:20:16

回答

1

您正在使用或代替and。

select email from mtn_extract_list_email 
     where (company like '%XYZ%' or office like '%XYZ%') 
     (email not like '%@aol%' AND email not like '%@gmail%' AND email not like '%@google%') 
     and (Country = 'USA' and rating like 'A%') 
     and email is not null;