有两个需要排序的字段。ID和ShowID
我想先按照ID的desc排列出来的结果然后再按ShowID的asc来排。
select * form table Where 条件 Order by ID desc,ShowID asc是不对的。
也就是我是要选按ID的排序查询出来然后再进行ShowID的排序。

解决方案 »

  1.   

    select *
    ,row_number() over(order by id desc)
    ,row_number() over(order by ShowID)
    from  table Where 条件 
      

  2.   

    刚才试了,不行。
    我的意思就是取出最新的4条记录,然后这个4条记录再按照ShowID字段的排序的显示出来
      

  3.   

    这样
    select * from (select top 4  * from table Where 条件 order by id desc) order by ShowID
      

  4.   

    关键字 'order' 附近有语法错误。
      

  5.   

    select * from (select top 4  * from table Where 条件 order by id desc) order by ShowID丢了个别名
      

  6.   


    select * from (select top 4 * from table where 条件 order by ID desc) order by ShowID asc 
      

  7.   

    select top 4 * from tb where 条件 order by id desc,showid asc
    这样不可以么
      

  8.   


    select * from (select top 4 * from table where 条件 order by ID desc) a order by ShowID asc