我有一个MySQL查询
select query from HR_Health_Logs where query REGEXP 'CPU|MAC|PC|abacus|calculator|laptop|mainframe|microcomputer|minicomputer|machine';
除了正则表达式更长,并且包含许多同义词和拼写错误。
我需要缩短这个简短的内容,并有一个包含所有同义词和拼写错误的表格,以便我可以避免这个非常长的查询。所以我正在寻找像
这样的东西select query from HR_Health_Logs where query REGEXP '**HAVE A TABLE WITH ALL MY SYNONYMS AND MISSPELLINGS SEARCHED HERE**';
答案 0 :(得分:3)
ANY
function怎么样?
select query from HR_Health_Logs where query REGEXP ANY (SELECT spell FROM misspelled WHERE correct = 'masturbate' ) ;
答案 1 :(得分:1)
SELECT query
FROM HR_Health_Logs l, synonym s
WHERE l.query = s.synonym
答案 2 :(得分:0)
SELECT query
FROM HR_Health_Logs
WHERE query IN (
SELECT synonym AS query
FROM synonyms_table
WHERE word = 'masturbation'
UNION
SELECT misspelling AS query
FROM misspellings_table
WHERE word = 'masturbation'
)
假设您的同义词和拼写错误位于两个单独的表中。否则,您将只使用其中一个子查询并删除UNION。