如 搜索结果为
字段 a   b
     1   x
     2   y
     3   z
     4   y
     5   x但我想按这样顺序排列: 字段b 为y的数据排在最先然后是x最后z ,只用oder by不行.
字段 a  b
     2  y
     4  y
     1  x
     5  x
     3  z
不知如何实现,,请各位多多指教.

解决方案 »

  1.   

    order by decode(b,'y','0'||b,'1'||b)oracle 里面ok
      

  2.   

    可以解释下decode(b,'y','0'||b,'1'||b)么, 
    b,'y','0' 
    b,'1'
    都什么意思..谢谢
      

  3.   

    create table t(a int, b varchar2(10));
    insert into t
    select 1,'x' from dual union all
    select 2,'y' from dual union all
    select 3,'z' from dual union all
    select 4,'y' from dual union all
    select 5,'x' from dual;
    /
    select * from t order by decode(b,'y',0,'x',1,'z',2);
    /
    2 y
    4 y
    1 x
    5 x
    3 z
      

  4.   

    decode(b,'y','0'||b,'1'||b)decode不用解释了吧,把b里面等于y的值前面加0,别的值前面加1,作为排序字段。如果特殊的不止y,就一个一个加上去
    --------------
    楼上的只能局限于x,y,z
    我这样,就是针对y和y以外的数据。
      

  5.   

    decode(字段1,判断1,值1,判断2,值2,默认值)字段1=判断1的时候,这个函数返回值1,
    字段1=判断2的时候,这个函数返回值2,

    字段1不在判断1~N的里面,返回默认值。
    下面的运行以下就知道了。select decode(1,'1','a','2','b','c') from dual
    select decode(2,'1','a','2','b','c') from dual
    select decode(3,'1','a','2','b','c') from dual
    select decode(4,'1','a','2','b','c') from dual