如 搜索结果为
字段 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
不知如何实现,,请各位多多指教.
字段 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
不知如何实现,,请各位多多指教.
调试欢乐多
b,'y','0'
b,'1'
都什么意思..谢谢
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
--------------
楼上的只能局限于x,y,z
我这样,就是针对y和y以外的数据。
字段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