SQL ROW_NUMBER() VS TOP

ROW_NUMBER() 的SQL语句:

 select * from (
     select ID , ArchivesTypeID,SegmentColumnName,SegmentDisplayText,SegmentOrderID,

     SegmentSeparator,ROW_NUMBER() over(order by  ID desc ) as RowNum   from MytestTable ) table1
 where RowNum  between  1700000 and  1710040

TOP 的SQL语句

 WITH temp AS (select ID , ArchivesTypeID,SegmentColumnName,SegmentDisplayText,

      SegmentOrderID,SegmentSeparator from MytestTable )
 select top  10040 * from  temp where id>(
     select max(id) from (select top  1700000 ID from temp order by id)table2
 ) order by ID

记录的总条数 select COUNT(*) from MytestTable 共2399998

ROW_NUMBER()用时2秒

TOP用时0秒

posted @ 2010-10-28 11:08  啊汉  阅读(660)  评论(0编辑  收藏  举报