SQLServer中,怎样搜索出500条记录中的,第20-40条呢? 
拜谢!

解决方案 »

  1.   

    select top 40 * from (select top 500 * from tb)tb where not exists(select top 21 * from tb)
      

  2.   

    select top 20 * from
    (500条的语句生成的记录集) x
    where id>(select max(id) from (select top 20 id from (500条的语句生成的记录集) y)m)
    我这里假设你的500条的记录集以id排序顺序取出.如果以其它条件,则写法相似。
    比如
    500条的语句是  
    select top 500 *,(getAmount-sendAmount) dAmount from tb where state=1 order by dAmount那么上面的语句,将所有的 id改为damount.
      

  3.   


    select * from (select top 40 * from 500条临时表)tb where id not in (select top 21 id from 500条临时表)