【发布时间】:2015-10-15 20:00:47
【问题描述】:
我有一张这样的桌子:
// mytable
+----+---------+-------------------------------+
| id | title | content |
+----+---------+-------------------------------+
| 1 | hello | how are you? |
| 2 | you | it is content2 |
| 3 | what | hello is a word for greating |
| 4 | mouse | it is content4 |
+----+---------+-------------------------------+
嗯,我想给title 比content 更优先。我的意思是,我想显示来自title 列的所有结果(第一个),然后显示来自content 列的所有结果(第二个)。这也是我的查询:
select * from mytable where match(title, content) against($word);
这里还有两个例子:
示例 1:
$word = 'you';
我想要这个输出:(专注于排序)
+----+---------+-------------------------------+
| id | title | content |
+----+---------+-------------------------------+
| 2 | you | it is content2 |
| 1 | hello | how are you? |
+----+---------+-------------------------------+
示例 2:
$word = 'hello';
我想要这个输出:(专注于排序)
+----+---------+-------------------------------+
| id | title | content |
+----+---------+-------------------------------+
| 1 | hello | how are you? |
| 3 | what | hello is a word for greating |
+----+---------+-------------------------------+
我再次强调,我想要所有来自title 列的结果,然后所有来自content 列的结果。有什么解决办法吗?
【问题讨论】:
-
为什么不按特定值在一个选择中按列排序?
标签: mysql sorting full-text-search sql-order-by