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

解决方案 »

  1.   

    select * from A where ID>=31 and ID<=40
      

  2.   


    select top 10 * from (select top 40 * from 表名 order by id)a order by id desc--orselect top 10 * from 表名 
    where id not in(select top 30 id from 表名 order by id) order by id
      

  3.   

    select top 10 * from tab where PKID>30 select * from tab where PKID between 31 and 40select 40 * from tab execpt select top 30 * from tab
      

  4.   

    参考:
    http://whx.tzgt.gov.cn/newOperate/html/3/33/331/11880.html其中的T-SQL你可以照抄。不过人家使用Linq to SQL,更方便地变化程序思路。
      

  5.   

    select top 10 * from (select top 40 * from 表名 order by id)a order by id desc
      

  6.   

    select a.* from
    (select top 40 * from tab) a left join (select top 30 * from tab) b
    on a.id=b.id where b.id is null