我有下表Foobar看起来像这样:
+----+-------------+
| ID | Description |
+----+-------------+
| 12 | aab |
+----+-------------+
| 13 | fff |
+----+-------------+
| 14 | fff |
+----+-------------+
| 15 | xab |
+----+-------------+
Run Code Online (Sandbox Code Playgroud)
我想要的是按顺序打印出所有描述.但是我首先要把值"fff"放在最顶层.换句话说,输出应如下:fff,fff,aab,xab.
所以很简单:"SELECT foobar.description FROM foobar ORDER BY foobar.description ASC"将无效.
jue*_*n d 10
在MySQL中这是有效的
SELECT foobar.description
FROM foobar
ORDER BY foobar.description <> 'fff',
foobar.description ASC
Run Code Online (Sandbox Code Playgroud)
但一般来说你也可以使用 case
SELECT foobar.description
FROM foobar
ORDER BY case when foobar.description = 'fff' then 1 else 2 end,
foobar.description ASC
Run Code Online (Sandbox Code Playgroud)