MySql-首先按字符串值排序 [英] MySql - order by string value first
本文介绍了MySql-首先按字符串值排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下面的表格Foobar,如下所示:
I've got the following table Foobar that looks like this:
+----+-------------+
| ID | Description |
+----+-------------+
| 12 | aab |
+----+-------------+
| 13 | fff |
+----+-------------+
| 14 | fff |
+----+-------------+
| 15 | xab |
+----+-------------+
我想要的是按顺序打印所有描述.但是,我首先希望值"fff"位于顶部.换句话说,输出应如下所示:fff,fff,aab,xab.
What I would like is to print out all the descriptions in order. However I would first of all like the values "fff" to be right at the top. In other words the output should be as follows: fff, fff, aab, xab.
如此简单:从foobar ORDER BY foobar.description ASC选择SELECT foobar.description"将不起作用.
So a simple: "SELECT foobar.description FROM foobar ORDER BY foobar.description ASC" will not work.
推荐答案
在MySQL中行之有效的
In MySQL this works
SELECT foobar.description
FROM foobar
ORDER BY foobar.description <> 'fff',
foobar.description ASC
但是通常您也可以使用case
But generally you can also use a case
SELECT foobar.description
FROM foobar
ORDER BY case when foobar.description = 'fff' then 1 else 2 end,
foobar.description ASC
这篇关于MySql-首先按字符串值排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文