Reputation: 381
I have a table like below. How to sort the column key as F,W,H?
Upvotes: 0
Views: 1411
Reputation: 32003
use decode
select a.* from yourtablename a
order by decode(Key,'F',1,'W',2,'H',3)
or
order by instr('FWH',Key)
Upvotes: 0
Reputation: 29
try this one:
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;
Upvotes: 1
Reputation: 37473
You can try using case when
expression in order by
clause
select * from tablename
order by case when key='F' then 1 when key='W' then 2 when key='H' then 3 end
Upvotes: 0