利用SQL语句对不同数据库进行高效果分页
发布时间:2008-11-28 14:44:00
在程序的开发过程中,处理分页是大家接触比较频繁的事件,因为现在软件基本上都是与数据库进行挂钩的。但效率又是我们所追求的,如果是像原来那样把所有满足条件的记录全部都选择出来,再去进行分页处理,那么就会多多的浪费掉许多的系统处理时间。为了能够把效率提高,所以现在我们就只选择我们需要的数据,减少数据库的处理时间,以下就是常用SQL分页处理:
1、SQL Server、Access数据库
这都微软的数据库,都是一家人,基本的操作都是差不多,常采用如下分页语句:
PAGESIZE:每页显示的记录数
CURRENTPAGE:当前页号
数据表的名字是:components
索引主键字是:id
select top PAGESIZE * from components where id not in
(select top (PAGESIZE*(CURRENTPAGE-1))
id from components order by id)order by id
如下列:
select top 10 * from components where id not in
(select top 10*10 id from components order by id)
order by id
从101条记录开始选择,只选择前面的10条记录
2、Oracle数据库
因为Oracle数据库没有Top关键字,所以这里就不能够像微软的数据据那样操作,这里有两种方法:
(1)、一种是利用相反的。
PAGESIZE:每页显示的记录数
CURRENTPAGE:当前页号
数据表的名字是:components
索引主键字是:id
select * from components where id not
in(select id from components where
rownum<=(PAGESIZE*(CURRENTPAGE-1)))
and rownum<=PAGESIZE order by id;
如下例:
select * from components where id not in
(select id from components where rownum<=100)
and rownum<=10 order by id;
从101到记录开始选择,选择前面10条。
(2)、使用minus,即中文的意思就是减去。
select * from components where rownum
<=(PAGESIZE*(CURRENTPAGE-1)) minus
select * from components where rownum
<=(PAGESIZE*(CURRENTPAGE-2));
如例:select * from components where
rownum<=10 minus select * from components
where rownum<=5;.
(3)、一种是利用Oracle的rownum,这个是Oracle查询自动返回的序号,一般不显示,但是可以通过select rownum from [表名]看到,注意,它是从1到当前的记录总数。
select * from (select rownum tid,components.
* from components where rownum<=100) where tid<=10;
猜你喜欢
- 在keras中,数据是以张量的形式表示的,不考虑动态特性,仅考虑shape的时候,可以把张量用类似矩阵的方式来理解。例如[[1],[2],[
- 1. 判断表单元素是否存在(一) if("periodPerMonth" in document.theForm) {
- MediaPipe概述谷歌开源MediaPipe于2019年6月首次推出。它的目标是通过提供一些集成的计算机视觉和机器学习功能,使我们的生活
- 一、dlib以及opencv-python库安装介于我使用的是jupyter notebook,所以在安装dlib和opencv-pytho
- 加上这句代码:print torch.cuda.is_available()判断完毕!说说在pytorch中如何查看gpu信息吧~为什么将数
- 缺省的情况下GitLab的官方镜像中提供了一个Redis,如果希望把此缓存数据库放在GitLab的容器之外的话需要怎么做呢?这篇文章结合示例
- 本文实例讲述了Python实现的爬取豆瓣电影信息功能。分享给大家供大家参考,具体如下:本案例的任务为,爬取豆瓣电影top250的电影信息(包
- requestRequests 是使用 Apache2 Licensed 许可证的 基于Python开发的HTTP 库,其在Python内置
- 首先为什么会有axis这个概念?因为在numpy模块中,大多数处理的是矩阵或者多维数组,同时,对多维数组或者矩阵的操作有多种可能,为了帮助实
- 由于tensorflow版本不同,可能一些函数的调用也有变换,这时候可能需要查看tensorflow版本,可以在终端输入查询命令如下:imp
- 本文实例讲述了Python实现的自定义多线程多进程类。分享给大家供大家参考,具体如下:最近经常使用到对大量文件进行操作的程序以前每次写的时候
- 一、数据地址实体抽取的目的及问题对数据的地址进行实体识别,主要作用是确定我们的数据主体最终可以归到哪一行政单位,从而在各行政单位上对数据主体
- 先来看看微信读书的效果实现思路这个效果比较简单,主要是旋转view,然后在旋转结束后更换view的背景,考虑到需要旋转view,所以使用动画
- 本文为大家分享了Win中安装mysql的详细步骤,供大家参考,具体内容如下mysql下载目录选择免安装版“Windows (x86, 64-
- 一、数据库是什么?数据库是管理数据的一类软件。对数据的管理体现在两个方面,第一是描述数据,即一条数据如何表示,第二是组织数据,即很多数据如何
- 引文之前将PHP反序列化的基础知识讲了一遍,不知道大家学习的怎么样了,今天给大家带来PHP反序列化的进阶知识:PHAR反序列化,也是之前本人
- 安装Pycharm进行Python开发时,经常右下角提示No R interpreter defined,处理方式:1、安装R,然后将R的路
- 本文介绍如何利用带进度条的ASP无组件实现断点续传下载大文件。<%@LANGUAGE="VBSCRIPT"&nbs
- staytime.asp<% If Request.QueryString("time")&n
- 一、JSP EL语言定义 E L(Expression