有没有办法用Access查询或SQL选择预期的记录?
Access 2010
实际记录数:万千订单
id | word |
---|---------------|
1 | green |
2 | light |
3 | greenlight |
4 | redlight |
5 | greenLEDlight |
6 | reddiamond |
实际记录数:千位
listword |
-------- |
green |
light |
1)选择以下内容,不包括仅包含“listword”的“word”,包括连接它们的那些(*)
id | word |
---|---------------|
4 | redlight |
5 | greenLEDlight |
6 | reddiamond |
2)或者,只选择“单词”,其中只有“listword”,包括连接它们的那些(*)
id | word |
---|---------------|
1 | green |
2 | light |
3 | greenlight |
(*)“green”或“light”或“greenlight”或“lightgreen”
SELECT words.id, words.word
FROM words, whitelist
WHERE not exists (
SELECT listword
FROM whitelist
WHERE word Like "*" & [listword] & "*"
)
GROUP BY words.id, words.word;
id | word |
---|---------------|
6 | reddiamond |
答案 0 :(得分:0)
这两个查询是否会返回您要查找的内容?
1)
SELECT id, word
FROM words
WHERE not exists (
SELECT *
FROM whitelist
WHERE listword = word
)
and not exists (
SELECT *
FROM whitelist w1, whitelist w2
WHERE w1.listword & w2.listword = word
)
2)
SELECT id, word
FROM words
WHERE exists (
SELECT *
FROM whitelist
WHERE listword = word
)
or exists (
SELECT *
from whitelist w1, whitelist w2
WHERE w1.listword & w2.listword = word
)
此代码将检查白名单上的简单单词以及“精确”对的存在,如“greenlight”。但如果你还需要检查像“greenlightgreen”这样的三胞胎,那么会失败。您可以添加三次或更多次白名单表的新子查询,但是有数千条记录会非常慢。