id    type_id
1       3
2       8
3       2
6       1
11      3
64      4
113     3
768     3     
2222    5
我想用一条语句。把type_id为3,id大的往前排。请问如何?

解决方案 »

  1.   

    select * from a where type_id=3 order by id desc
      

  2.   

    select * from tt order by type_id,id desc
      

  3.   

    额。。这个   我type_id不为3的也要排在后面
      

  4.   

    id type_id
    1    3
    2    8
    3    2
    6    1
    11   3
    64   4
    113  3
    768  3  
    2222 5
    这个是原始的id   type_id
    768     3  
    113     3
    11      3
    1       3
    2222    5
    64      4
    6       1
    3       2
    2       8
    这个是排序后的
      

  5.   

     (不要高估你的汉语表达能力或者我的汉语理解能力)
       建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  6.   

    select * from a where type_id=3 order by id desc
    union all
    select * from a where type_id <>3
      

  7.   

    select *
    from table1
    order by  type_id=3 desc,id desc
      

  8.   

    解决了。多谢各位。才知道可以多次order by
      

  9.   


    order by id DESC,type_id ASC
    才知道原来可以这样写··