现在DB中有如下数据:
1

3
9997
9998
9999希望出来的结果是:
9997
9998
9999
1
2
3请大侠指点SQL如何写?

解决方案 »

  1.   

    select a from table_name where a>9000 order by a
    union
    select a from table_name where a<9000 order by a
      

  2.   

    select * from T
    order by length(a) desc,a
      

  3.   

    select * from T
    order by substr(a,1,1) desc,substr(a,length(a)-1,1)
    不知行不?
      

  4.   

    楼主是想实现一个循环的链式排序吧?我没有试过,不过你可以试试,如果你要对10000个数进行这样的排序,试试如下与句:select c_name,
    case when c_name >= 10000 / 2 then c_name - 10000
         when c_name < 10000 / 2 then c_name + 10000
         end c_order
     from t_name order by c_order;这样对上面的例子可以