mysql—如何按手动顺序获取一些行,然后按常规方式进行休息

beq87vna  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(275)

我从数据库中得到了一些国家,我想用手把其中的一些放到开头。列表应该是这样的:

Y <- those rows should be chosen by hand
X
R 
A <- and the rest is going to be in the regular order
B
C
D
oipij1gg

oipij1gg1#

你可以使用 case 表达式:

select t.*
from t
order by (case when col = 'Y' then 1
            when col = 'X' then 2
            when col = 'R' then 3
            else 4
       end),
      col;

相关问题