如何在 sqlite3 的 WHERE 子句中添加多个“NOT LIKE '%?%'? [英] How do I add multiple "NOT LIKE '%?%' in the WHERE clause of sqlite3?

查看:80
本文介绍了如何在 sqlite3 的 WHERE 子句中添加多个“NOT LIKE '%?%'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 sqlite3 查询,例如:

I have a sqlite3 query like:

SELECT word FROM table WHERE word NOT LIKE '%a%';

这将选择单词中不出现 'a' 的所有单词.这我可以完美地工作.问题是我是否想进一步限制结果,使其不包含单词中的任何地方的b".我正在想象这样的事情.

This would select all of the words where 'a' does not occur in the word. This I can get to work perfectly. The problem is if I want to further restrict the results to not include 'b' anywhere in the word. I am picturing something like this.

SELECT word FROM table WHERE word NOT IN ('%a%', '%b%', '%z%');

这显然行不通,但这就是想法.只是添加一个 AND 子句是我试图避免的:

which this obviously does not work, but this is the idea. Just adding an AND clause is what I'm trying to avoid:

SELECT word FROM table WHERE word NOT LIKE '%a%' AND NOT LIKE '%b%';

如果这是唯一的选择,那么我将不得不使用它,但我希望有别的选择.

If this is the only option then I will have to work with that, but I was hoping for something else.

推荐答案

如果您使用 Sqlite 的 REGEXP 支持(请参阅 regexp python 和 sqlite 的问题 如何做到这一点 ) ,那么你可以在一个子句中轻松做到:

If you use Sqlite's REGEXP support ( see the answer at Problem with regexp python and sqlite for how to do that ) , then you can do it easily in one clause:

SELECT word FROM table WHERE word NOT REGEXP '[abc]';

这篇关于如何在 sqlite3 的 WHERE 子句中添加多个“NOT LIKE '%?%'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆