现在数据库的数据为:
1
1-1
1-2
1-1-1
2
2-1
3
4
5
6
7
8
9
10
11
……需要请上述内容按升序排序成下列结果:
1
1-1
1-1-1
1-2
2
2-1
3
4
5
6
7
8
9
10
11
……
请问有什么好方法?谢谢

解决方案 »

  1.   

    select * from 表名order by 要排序的字段
      

  2.   

    select a, b from (
    select a, '0'||a b from xx where lengthb(a)>1 and substrb(a,2,1)>='1' and substrb(a,2,1)<='9' union select a, '0'||a b from xx where lengthb(a)=1 union select a,a b from xx where lengthb(a)>1 and (substrb(a,2,1)<'1' or substrb(a,2,1)>'9') ) order by b只用a列即可。
    但只对100以下有效,且-后面的数字也只能到9,呵呵。
      

  3.   

    select a, b from (
    select a, a b from xx where lengthb(a)>1 and substrb(a,2,1)>='1' and substrb(a,2,1)<='9' union select a, '0'||a b from xx where lengthb(a)=1 union select a,'0'||a b from xx where lengthb(a)>1 and (substrb(a,2,1)<'1' or substrb(a,2,1)>'9') ) order by b