数据库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)方式一
1 |
|
3. DB2分页查询
1 |
|
4. SQLServer分页查询
(1)SQLServer 2000
1 |
|
(2)SQLServer 2005
1 |
|
5. PostgreSQL分页查询
1 |
|
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;