id  type  
1    2
2    3
3    5
4    2
6    3
7    5
8    1
问题是这样的, 我现在想查询排序, type=3的优先(有多个type=3的情况下,这几个中再按id排序),接着是tpye=2的, 剩下type=其他的 按照id来排序 
在做一个网站  遇到这个问题   希望有大神帮忙解决····· 谢谢了

解决方案 »

  1.   

    结果应该是
     id type
     2   3
     6   3
     1   2
     4   2
     3   5
     7   5
     8   1
      

  2.   


    select id, type from t where type <= 3 and type >= 2 order by type desc, id
    UNION
    select id, type from t where type <2 or type >3 order by type desc, id
      

  3.   

    select * from tbl_name order by type='3' desc, type='2' desc, id