直接让代码了,对比看看就了解了
当然,这种情况比较适合提取字段较多的情况,要酌情而定
性能较差的:
WITH # temp AS ( Select column1,column2,column3,column4,column5,column6,column7,column8,column9,column10, row_number() over ( Order by column100 desc ) as RowNumber From tables1 Where ..... ) SELECT * FROM # temp WHERE RowNumber BETWEEN 1601 and 1620 ORDER BY RowNumber |
优化后,性能较好的
WITH # temp AS ( Select column1, row_number() over ( Order by column100 desc ) as RowNumber From tables1 Where ..... ) SELECT column1,column2,column3,column4,column5,column6,column7,column8,column9,column10 FROM tables1 where column1 in ( select column1 from # temp WHERE RowNumber BETWEEN 1601 and 1620 ORDER BY RowNumber ) |