sqlserver 分页修改
时间: 2023-10-06 10:11:08 浏览: 84
SQL server分页
SQL Server 分页可以使用 OFFSET FETCH 或 ROW_NUMBER 函数来实现:
使用 OFFSET FETCH:
```
SELECT column1, column2, ...
FROM table_name
ORDER BY column_name
OFFSET (page_number - 1) * page_size ROWS
FETCH NEXT page_size ROWS ONLY;
```
其中,page_number 表示当前页码,page_size 表示每页的记录数。
使用 ROW_NUMBER:
```
SELECT column1, column2, ...
FROM (
SELECT column1, column2, ..., ROW_NUMBER() OVER (ORDER BY column_name) as row_num
FROM table_name
) as temp_table
WHERE row_num BETWEEN ((page_number - 1) * page_size + 1) AND (page_number * page_size);
```
其中,ROW_NUMBER() OVER (ORDER BY column_name) 表示按照指定的列排序并分配行号,temp_table 为子查询的别名。
阅读全文