sql server实现分页的方法实例分析

作者:继续去踢波 时间:2024-01-26 11:36:26 

本文实例讲述了sql server实现分页的方法。分享给大家供大家参考,具体如下:


declare @index int,@num int
set @index = 1--当前页
set @num = 2--单页包含的行数
--分页1
select top (@num) *
from ppohd
where doccode not in
(
 select top (@num * (@index -1)) doccode
 from ppohd
 order by doccode
)
order by doccode
--分页2
select top (@num) *
from ppohd
where doccode >=
(
 select max(doccode)
 from
 (
   select top (@num * (@index - 1) + 1) doccode
   from ppohd
   order by doccode
 ) as tb
)
--分页3
select top (@num) *
from
(
 select ppohd.doccode as 'mydoccode',row_number() over (order by doccode) as sno,*
 from ppohd
) as tb
where tb.sno >= @num * (@index - 1) + 1
--分页4
select *
from
(
 select ppohd.doccode as 'mydoccode', row_number() over(order by doccode) as sno,*
 from ppohd
) as tb
where tb.sno between (@num * (@index - 1) + 1) and (@num * @index)

希望本文所述对大家SQL Server数据库程序设计有所帮助。

标签:sql,server,分页
0
投稿

猜你喜欢

  • Python用二分法求平方根的案例

    2021-09-27 10:05:01
  • Python使用正则表达式过滤或替换HTML标签的方法详解

    2023-02-08 10:49:52
  • Python深度学习实战PyQt5菜单和工具栏功能作用

    2021-04-04 16:09:40
  • Python计算一个点到所有点的欧式距离实现方法

    2023-03-29 21:19:11
  • 费茨法则在交互设计中的应用

    2009-07-09 19:02:00
  • python实现进度条的多种实现

    2021-03-20 10:39:52
  • MySQL InnoDB 二级索引的排序示例详解

    2024-01-15 17:11:53
  • Microsoft .Net Remoting系列教程之一:.Net Remoting基础篇

    2024-05-09 09:03:35
  • python为tornado添加recaptcha验证码功能

    2023-04-26 19:57:12
  • asp学习入门基本语法知识

    2007-11-07 14:02:00
  • Node.js中文件操作模块File System的详细介绍

    2024-05-13 10:04:47
  • 用Python创建简易网站图文教程

    2023-03-09 20:37:57
  • 解决vue打包之后静态资源图片失效的问题

    2024-05-29 22:18:53
  • python定向爬取淘宝商品价格

    2023-10-03 23:33:12
  • 小系统单据自动生成存储过程

    2024-01-16 23:16:17
  • Oracle终极彻底卸载的完整步骤

    2024-01-13 14:37:59
  • mysql-8.0.15-winx64 解压版安装教程及退出的三种方式

    2024-01-23 21:56:20
  • win7+Python3.5下scrapy的安装方法

    2023-06-05 02:02:41
  • 教你如何将 Sublime 3 打造成 Python/Django IDE开发利器

    2022-10-10 11:37:29
  • Golang Socket Server自定义协议的简单实现方案

    2024-04-25 13:17:40
  • asp之家 网络编程 m.aspxhome.com