questions
让我们有一个包含一列的简单 InnoDB 表text
,其中包含以下数据:
What color does the sun have?
What year it is?
What year was Barack Obama born?
Where in europe people speak french?
When stackoverflow started?
现在,我想搜索此列:
SELECT *
FROM `questions`
WHERE `text` LIKE '%What%' OR `text` LIKE '%year%';
但是,这会生成输出:
What color does the sun have?
What year it is?
What year was Barack Obama born?
我想要按搜索词的出现排序的输出。换句话说,当问题同时包含“什么”和“年份”时,它应该在只包含“什么”的问题之前。所以输出看起来像这样:
What year it is?
What year was Barack Obama born?
What color does the sun have?
只能使用 MySQL 来完成吗?如果没有,有没有使用 PHP 的好方法?