我有一张桌子:物品(ID,描述)。在我的程序中,我得到一个单词列表(word1 到 wordN)作为输入,我需要计算这些单词中有多少出现在表中的每个描述中,并根据该数字对结果进行排序。这是我的解决方案,但我欢迎有关如何提高性能的建议。谢谢。
SELECT x, COUNT(*)
FROM (SELECT description as x, id FROM items where description LIKE '%word1%'
UNION ALL
SELECT description as x, id FROM items where description LIKE '%word2%'
UNION ALL
...
UNION ALL
SELECT description as x, id FROM items where description LIKE '%wordN%')
GROUP BY (id)
ORDER BY COUNT(*) DESC