我找到了相关答案这里。
就我而言,我有一个表格列
comment
。如何将“我的评论”移至顶部,然后按 id
排序?
other comment my comment
other comment my comment
other comment my comment
my comment => other comment
other comment other comment
my comment other comment
my comment other comment
假设您的目标是:
“将‘我的评论’排序在其他评论之前,然后按
id
排序”
SELECT *
FROM comments
ORDER BY comment <> 'my comment', id;
boolean
false
(想想 0)在 true
(想想 1)之前排序。“将‘我的评论’排序在其他评论之前,然后按字母顺序对评论进行排序,然后按
id
排序”
SELECT *
FROM comments
ORDER BY comment <> 'my comment', comment, id;
参见(包含更多链接):