mysql - 在mysql查询中结合Not In和like函数

标签 mysql sql-like in-operator

我想知道是否有办法在 MySQL 中将 not in() 函数与 like 或通配符 * 合并?就像下面的查询一样:

select sl_tags from tablname
    where `sl_tags` not in ('%Soccer%','%Football%','%Hockey%','%shinny%','%Basketball%','%Volleyball%','%Cricket%')

以上查询不起作用。

我知道这有效

select sl_tags from tablname where `sl_tags` Not like '%Soccer%' and `sl_tags` Not like '%Football%' 

我在堆栈上看到了以前提出的问题和答案,但没有找到任何相关答案。

最佳答案

不,没有这样的运算符。

但是您可以使用 Regular Expressions 以稍微不同的方式执行此操作

SELECT sl_tags
  FROM tablname
  WHERE sl_tags NOT REGEXP 'Soccer|Football|Hockey|shinny|Basketball';

请注意,某些字符(例如点 .)具有特殊含义,需要为 escaped按字面意思使用。

关于mysql - 在mysql查询中结合Not In和like函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29030422/

相关文章:

PHP 从数据库导出 CSV 表

php - 取决于用户 ID

mysql - 对 Char 类型使用 Like 和 Concat

hadoop - Hive - LIKE 运算符

python - 覆盖 Python 的 'in' 运算符?

javascript - 删除数组索引的原型(prototype)也会删除数组索引

mysql - 获取两个表的总和 GROUP BY date in year

php - 为什么有那么多 PHP 站点只提供 MySQL 作为数据库?

python - 嵌套列表的 'in' 运算符的替代方案

mysql - 无法连接到mysql