数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

Oracle、MYSQL、sqlserver和DB2分页查询


发布日期:2018年04月27日
 
Oracle、MYSQL、sqlserver和DB2分页查询

DB:

DB分页查询

SELECT * FROM (Select 字段字段字段rownumber() over(ORDER BY 排序用的列名 ASC) AS rn from 表名) AS a WHERE arn BETWEEN AND

以上表示提取第的纪录

select * from (select rownumber() over(order by id asc ) as rowid from table where rowid <=endIndex ) where rowid > startIndex

如果Order By 的字段有重复的值那一定要把此字段放到 over()中

select * from ( select ROW_NUMBER() OVER(ORDER BY DOC_UUID DESC) AS ROWNUM DOC_UUID DOC_DISPATCHORG DOC_SIGNER DOC_TITLE from DT_DOCUMENT ) a where ROWNUM > and ROWNUM <=

增加行号不排序

select * from ( select ROW_NUMBER() OVER() AS ROWNUMt* from DT_DOCUMENT t ) a

增加行号按某列排序

select * from ( select ROW_NUMBER() OVER( ORDER BY DOC_UUID DESC ) AS ROWNUMt* from DT_DOCUMENT t ) a

Mysql:

最简单

select * from table limit startpageNum

比如从个数据

select * from table limit

Oracle

select * from (select rownumname from table where rownum <=endIndex ) where rownum > startIndex

例如从表Sys_option(主键为sys_id)中从条记录还是检索条记录语句如下

SELECT *

FROM (SELECT ROWNUM Rt* From Sys_option where rownum < ) t

Where tR >=

sql server:

例如从表Sys_option(主键为sys_id)中从条记录还是检索条记录语句如下

SELECT *

FROM (SELECT ROWNUM Rt* From Sys_option where rownum < ) t

Where tR >=

上一篇:oracle删除重复记录方法

下一篇:Oracle9i Database 自调整:Oracle SGA(上)