表a1
AA     BB     CC
a      1      22
b      33     6
b      3      6
c      3      4
a      5      5
想得出下面的结果集
AA     BB     CC
b      33     6
b      3      6
a      1      22
a      5      5
c      3      4
其实就是按字段AA里的a,b,c排序(字段AA只存在a,b,c三种值)怎么写SQL语句?

解决方案 »

  1.   

    select * from tablename 
    order by case when AA='a' then 1
                  when AA='b' then 2
                  when AA='c' then 3
          else 4 end
      

  2.   

    select AA,BB,CC from 表a1
    where AA='b' order by BB desc
    union alll
    select AA,BB,CC from 表a1
    where AA='a' order by BB 
    union alll
    select AA,BB,CC from 表a1
    where AA='c' order by BB ??