按特定顺序对值排序oracle sql

cu6pst1q  于 2021-07-26  发布在  Java
关注(0)|答案(3)|浏览(316)

我有一张像下面这样的table。如何将列键排序为f、w、h?

gywdnpxw

gywdnpxw1#

你可以试着用 case when 中的表达式 order by 条款

select * from tablename
order by case when key='F' then 1 when key='W' then 2 when key='H' then 3 end
crcmnpdw

crcmnpdw2#

试试这个:

select * from table1 where key in ('F','W','H')
order by case
when key ='F' then 1
when key ='W' then 2
else 3
end;
3npbholx

3npbholx3#

使用解码

select a.* from yourtablename a
order by decode(Key,'F',1,'W',2,'H',3)

order by instr('FWH',Key)

相关问题