sql查询表N到M行的数据,查询表内最新标识列

第一比较傻的方法

  select * from (select top (m-n+1) * from (select top m * from 表) a order by a.Id desc) b order by b.Id
  
第二有技术含量的方法

   select * from (select *,ROW_NUMBER() over (order by id)px from 表)as t where px>n and px<=m

第三种换个思路

  select top m-(n-1) * from 表 where id not in (select top n-1 id from 表 order by Id) order by Id

  --查询n到m行的数据


你是哪个...

  谁还有其他方法欢迎留言

加点内容

查询表内最新的标识列  有时候很有用 select IDENT_CURRENT('表名')

原文地址:https://www.cnblogs.com/zhang271123288/p/3625726.html