【发布时间】:2019-11-28 01:03:23
【问题描述】:
尝试为 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
【问题讨论】:
-
不要在一个字符串中存储多个值!您需要一个单独的表格,每个标签和每个名称都有一行。