为了清楚起见,我们假设我有一个像这样的表结构:
| 字 | 文件路径 |
==============
猫| /usr/share/something.txt
猫| /usr/share/anotherthing.txt
狗| /usr/share/something.txt
汽车| /usr/share/anotherthing.txt
我想要做的是,给定一个单词列表,我想得到文件路径列表,该文件中每个单词都存在,例如,给出一个“猫,狗”列表,我想得到“/usr/share/something.txt”而不是“/usr/share/anotherthig.txt”,因为anotherthing.txt中不包含单词 dog 。
答案 0 :(得分:0)
这会找到行
代码:
SELECT
*
FROM
MyTable M1
WHERE
M1.Word IN ('cat', 'dog')
AND
NOT EXISTS (SELECT *
FROM
MyTable M2
WHERE
M2.Word NOT IN ('cat', 'dog')
AND
M1.filepath = M2.filepath
);
答案 1 :(得分:0)
最简单的方法应该是按照计数与您搜索的单词数量进行匹配。
SELECT filepath,count(*) c FROM table WHERE word IN ('cat','dog') GROUP BY filepath HAVING c=2