rt
比如 表a    用户字段有a,b,c,d,e,f,z
这些记录 我要求按用户字段排序  但是要求f在第一个,其他的按字符串排序。就是 f a b c d e z怎么写?

解决方案 »

  1.   

    select col from table
    order by decode(col,'f','null',col) nulls first
      

  2.   


    select userid from tb
    order by decode(userid,'f',null,userid) nulls first
    --排序的时候如果是f的话转换成null 其他的不变 
    --nulls first表示null排在前面 nulls last 表示null排在后面
      

  3.   


    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
      

  4.   

    select userid from tb
    order by decode(userid,'f',null,userid) nulls first
      

  5.   


    学习了,但是LZ不是要f在前面嘛,要是转换成null,就不符合LZ的要求啦?
      

  6.   

    我们也用decode     我们的数据是  -1 ,0,1,2,3 排序  要0在最前。