数据库MySQL-Oracle-DB2-SQLServer分页查询

1. MySQL分页查询

(1)关键字: LIMIT beginIndex, maxRow

(2)示例:

LIMIT子句可以用来限制由SELECT语句返回过来的数据数量,它有一个或两个参数。
如果给出两个参数, 第一个参数指定返回的第一行在所有数据中的位置,从0开始(注意不是1),第二个参数指定最多返回行数
例如:
-- 从beginIndex行开始,查询maxRow行
select * from table limit beginIndex,maxRow

-- 从10行开始,查询20行;即查询10~30行的数据
select * from table limit 10,20
-- 返回前10行
select * from table WHERE … LIMIT 10; 
-- 返回前10行
select * from table WHERE … LIMIT 0,10;
-- 返回第10-30行数据
select * from table WHERE … LIMIT 10,20; 

2. Oracle分页查询

(1)方式一

select * from (select a.*,rownum rc from 表名 where rownum<=endrow) a where a.rc>=startrow

3. DB2分页查询

select * from (select rownumber() over() as rc,a.* from (select * from 表名 order by 列名) as a) where rc between startrow and endrow

 

4. SQLServer分页查询

(1)SQLServer 2000

select top pagesize * from 表名 where 列名 not in(select top pagesize*page 列名 from  表名 order by 列名) order by 列名

(2)SQLServer 2005

select * from (select 列名,row_搜索number() over(order by  列名1) as 别名from 表名) as t where t.列名1>=startrow and t.列名1<=endrow

5. PostgreSQL分页查询

select * from 表名 limit pagesize,offset startrow 

99. 通用分页SQL

select * from (
 select * from tb_student where sid not in(
     select sid from tb_student where rownum<=(currentPage-1)*pageSize)
) where rownum <=pageSize;
posted @ 2015-01-21 14:15  沙漏哟  阅读(1629)  评论(0编辑  收藏  举报