mysql查询返回多个LIKE表达式的错误结果

时间:2014-03-27 13:35:57

标签: mysql sql-like

我正在运行此查询

SELECT `contacts`.* 
FROM `contacts` 
WHERE 
    ((email NOT LIKE '%domain1%') AND 
     (email NOT LIKE '%domain2%') AND 
     (email NOT LIKE '%domain3%') AND 
     (email NOT LIKE '%domain4%')
    ) AND (
     DATE(created_at) = '2014-03-21'
    )

结果是

 => [["ram.kumar@domain1.com", Fri, 21 Mar 2014 06:17:07 UTC +00:00],  
     ["ram.kumar@domain2.com", Fri, 21 Mar 2014 17:05:21 UTC +00:00]] 

问题

  • 结果应排除所有行" domain1"," domain2"等等......但它没有这样做

PS:查询结果未显示为MySQL输出,因为我从rails控制台运行它。

Contact.external.created_on( Time.parse("2014-03-21 ")).collect {|e| [e.email, e.created_at]}

1 个答案:

答案 0 :(得分:1)

尝试使用OR条件

SELECT `contacts`.* 
FROM `contacts` 
WHERE 
    (email NOT LIKE '%domain1%' OR
     email NOT LIKE '%domain2%' OR 
     email NOT LIKE '%domain3%' OR 
     email NOT LIKE '%domain4%'
    ) AND (
     DATE(created_at) = '2014-03-21'
    )

"ram.kumar@domain1.com"不是,NOT LIKE '%domain4%'如果有意义