比如表 tab 有2个字段 a,b问题为当,a=1时,b倒序,a=2时,b顺序
我现在的做法是分开来,然后union all
如:
select aa.* from (
select * from tab where a=1 order b desc) aa
union all
select bb.* from (
select * from tab where a=2 order by b asc)) bb
这样如果字段多的话,sql会很长,有没有别的方法了尼
我现在的做法是分开来,然后union all
如:
select aa.* from (
select * from tab where a=1 order b desc) aa
union all
select bb.* from (
select * from tab where a=2 order by b asc)) bb
这样如果字段多的话,sql会很长,有没有别的方法了尼
你的需求应该是没有说完!
select tab.a,tab.b,tab.c,tab.d,tab.e,tab.f,tab.g,tab.h,tab.i,tab.j,tab.k,tab.l,tab.m,tab.n,tab.p... from tab
select tab.a,tab.b,tab.c,tab.d,tab.e,tab.f,tab.g,tab.h,tab.i,tab.j,tab.k,tab.l,tab.m,tab.n,tab.p... from tab
select tab.a,tab.b,tab.c,tab.d,tab.e,tab.f,tab.g,tab.h,tab.i,tab.j,tab.k,tab.l,tab.m,tab.n,tab.p... from tab
这只是写的列名多而已,性能上不比 select * 差。而且推荐这种直接指定要查询的列的方法
select tab.a,tab.b,tab.c,tab.d,tab.e,tab.f,tab.g,tab.h,tab.i,tab.j,tab.k,tab.l,tab.m,tab.n,tab.p... from tab
你这个是业务上的需要,该写就写吧;
order by decode(a,1,-b,b)
只有decode(a,1,-b,b),是不行的