order-by——不同条件的不同序列

xqkwcwgp  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(403)

我想这样做:

select a
from table
order by
 case when a='A' then b,c,d
 else d,c,b

a、 b,c,d都是表中的列。

myss37ts

myss37ts1#

你的问题不是很清楚你真正期望的结果,但我怀疑是:

order by
    case when a = 'A' then b else d end,
    c,
    case when a = 'A' then d else b end

或者如果你想要记录在哪里 a = 'A' 首先(按指定顺序),然后是其余记录(按其他顺序),然后:

order by
    case when a = 'A' then 0 else 1 end,
    case when a = 'A' then b else d end,
    c,
    case when a = 'A' then d else b end

相关问题