select top 5 * from (select top 15 * from tableNameorder by id asc) tableName order by id desc

 

 

或者类似用select top 方式的分页储存过程

 

 

SQL Server2005 中row_number函数的诞生,在处理分页上简化了很多语句

 

 

row_number函数的用途是非常广泛,这个函数的功能是为查询出来的每一行记录生成一个序号。row_number函数的用法如下面的SQL语句所示:

 

 

没有使用row_number函数

 

SELECT * FROM tableName

 

 

最精简的分页处理方式

 

 

使用row_number函数

 

 

 

select row_number() over(order by id) as row_number,* from tableName

 

最精简的分页处理方式

 

 

其中row_number列是由row_number函数生成的序号列。在使用row_number函数是要使用over子句选择对某一列进行排序,然后才能生成序号。

相关文章:

  • 2021-11-20
  • 2022-12-23
  • 2022-01-05
  • 2021-06-06
  • 2022-12-23
  • 2021-09-30
  • 2022-03-08
  • 2022-12-23
猜你喜欢
  • 2021-06-28
  • 2022-02-13
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案