写出一条Sql语句:取出表A中第31到第40记录(SQLServer,以自动增长的ID作为主键,注意:ID可能不是连续的。

答:解1:  select top 10 * from A where id not in (select top 30 id from A)

    解2:  select top 10 * from A where id > (select max(id) from (select top 30 id from A )as A)

首先就拿解1来select top 10 * from A表示取出前十条的数据

select top 30 id from A表示取出前30条的数据

现是取出大于30条的数据并且在取出大于10条的数据并且这个1条的数据是在30条数据之外的数据也就是说31-41之间的数据

原文地址:https://www.cnblogs.com/BoYu045535/p/3591035.html