10条数据(乱序),要以升序排列并且查询第4、5、6条数据
在SQL Server中应该怎么写?

解决方案 »

  1.   

    select * from
    (select *,row_id=row_number() over(order by 排序字段) from tb) t
    where row_id in(4,5,6)
      

  2.   


    select * from 
    (select row_number() over(order by 排序列) rn,*
    from 你的表 )t
    where rn between 4 and 6;
      

  3.   


    --2
    select top 3 * from
    (select top 6 * from tb order by 字段) t
    order by 字段 desc
      

  4.   


    select * from
    (select *,row_id=row_number() over(order by col) from tb) t
    where row_id in(4,5,6)--orselect top 3 * from
    (select top 6 * from tb order by col) t
    order by col desc