python-3.x - 在 SQLite3 中,如何选择匹配列表的任何项目?
问题描述
我使用“sqlite3”来访问 Python 程序中的数据库。我有一个关键字列表,例如,
fruit=['banana','apple','orange'] #the total number is 50.
如果我有下表:
Col 1 | Col 2
'this is a desk' | something else
'banana is good for health' | something else
'bad apple' | something else
如何选择 Col 1 包含水果中的任何项目的行,例如在此示例中,应选择第 2 行和第 3 行?
我知道一个项目的“LIKE”命令,例如
SELECT * FROM table WHERE Col 1 LIKE '%banana%'
但我不知道如何使用列表来做到这一点。
解决方案
使用OR运算符选择具有不同值的行。
SELECT "Col 1"
FROM table
WHERE
"Col 1" LIKE '%banana%' OR
"Col 1" LIKE '%apple%' OR
"Col 1" LIKE '%orange%'
推荐阅读
- mysql - 如何使用mysql sum() 函数计算每一行的总和?
- angular - Angular 中的依赖注入有什么用,因为它显然没有解决任何问题?
- java - 为什么 Iterators.size() 使迭代器为空?
- r - 告诉哪些行是不同的,同时保持 ID 变量
- kubernetes - Fetching Stackdriver Monitoring TimeSeries data for a pod running on a k8s cluster on GKE using the REST API
- visual-studio - 如何重命名 Visual Studio
- ios - Flutter plugin configuration issue
- perl - 将多元素字符串拆分为哈希
- javascript - Responsive elements hidden when no space
- json - Kafka Topic Message Versioning