select col from table order by decode(col,'f','null',col) nulls first
select userid from tb order by decode(userid,'f',null,userid) nulls first --排序的时候如果是f的话转换成null 其他的不变 --nulls first表示null排在前面 nulls last 表示null排在后面
with tab as(select 'a' col from dual union all select 'f' from dual union all select 'b' from dual union all select 'g' from dual) select * from tab order by decode(col,'f',0,1),col ------------------------------------------------------ col --- f a b g
select userid from tb order by decode(userid,'f',null,userid) nulls first ;
order by decode(col,'f','null',col) nulls first
select userid from tb
order by decode(userid,'f',null,userid) nulls first
--排序的时候如果是f的话转换成null 其他的不变
--nulls first表示null排在前面 nulls last 表示null排在后面
with tab as(select 'a' col from dual union all select 'f' from dual union all select 'b' from dual union all select 'g' from dual)
select * from tab order by decode(col,'f',0,1),col
------------------------------------------------------
col
---
f
a
b
g
order by decode(userid,'f',null,userid) nulls first
;
学习了,但是LZ不是要f在前面嘛,要是转换成null,就不符合LZ的要求啦?