sql - SQLite 子查询,具有可变数量的输入
问题描述
尝试为 SQLite 数据库构建 SQL 查询,该查询将获取主题名称并将返回所有匹配的行,而不管主题记录中的单词顺序如何。以下查询对 2 个输入按预期工作。
select name
from
(select name from students where tags like "%biology%")
where
tags like "%physics%"
如果按如下方式传入 3 个主题输入,则Geo Math Zoo
必须通过代码扩展上述查询(在这种情况下使用 Python)。有没有更好的选择来处理 9 到 10 范围内的输入案例数量?
Student
桌子:
Name Sub
-------------------------------------------
S1 Biology Math Geo Physics
S2 Math Geo Physics
S3 Biology Geo Math Physics Zoo -- should be in output
S4 Biology Physics Math Geo
S5 Biology Zoo Math Geo -- should be in output
解决方案
您可以使用OR
运算符搜索多个条件:
select *
from students
where tags like "%biology%"
or tags like "%physics%"
推荐阅读
- c# - 如何在 ASP.NET Core + Kestrel + Nginx 中使用自定义域
- android - 当我将自定义 LocationDataSource 设置为 PositioningManager 时,HERE SDK NavigationManager 停止工作
- google-analytics-api - 权限错误:权限被拒绝:'analyticsreporting.dat'
- php - 自动选择图像
- javascript - 访问时出现流错误,可能键入在真实检查后定义的函数表达式
- python - 从生成器创建一个 dask bag
- sql-server - 我需要从字符串集中计算出的值
- docker - Docker info 和 Docker ps 显示不同数量的正在运行的容器
- red - 列的红色 vid 布局
- python - 使用 dict 理解初始化类字典 - 范围