如果不提供有关表结构外观的更多详细信息,这只能是模糊的回答。
但是,如果您的数据基于类似字符串的数据类型,请考虑使用全文索引。
基本示例。your_field
在全文索引中。
+----+-------------------------------------------------------------+
| id | your_field |
+----+-------------------------------------------------------------+
| 1 | red |
| 2 | green red |
| 3 | black red |
| 4 | yellow red green blue orange |
| 5 | black blue |
+----+-------------------------------------------------------------+
现在是 SQL:
SELECT *,
MATCH (your_field)
AGAINST ('+yellow +red +green +blue +orange' IN BOOLEAN MODE) AS 'val'
FROM yourtable
WHERE MATCH (your_field)
AGAINST ('+yellow +red +green +blue +orange' IN BOOLEAN MODE)
ORDER BY val DESC;
更多信息可以在手册中找到。