富贵资源网 Design By www.hznty.com

先来定义分页语句将要用到的几个参数:

int currentPage ; //当前页
int pageRecord ; //每页显示记录数

以之前的ADDRESSBOOK数据表为例(每页显示10条记录):

一、SqlServe下载 分页语句

String sql = "select top "+pageRecord +" * from addressbook where id not in (select top "+(currentPage-)*pageRecord +" id from t_user)"; 
// (currentPage-)*pageRecord : 是指从第几个记录开始 

第二页SQL演示:

select top 20 * from addressbook where id not in (select top 10 id from addressbook)

二、MySQL数据库分页语句

String sql = "select * from addressbook where limit "+(currentPage-)*pageRecord +","+pageRecord +""; 
//select * from 表名 【条件】limit M,N; 
//M为从第几个记录开始,比如每页显示条记录,第二页就必须从第条记录开始 
//N每页读几个数据 

第二页SQL演示:

select * from addressbook where limit 10,10

三、Oracle数据库分页语句

String sqls = "select * from ( select rownum rn,t.* from addressbook t where rownum <= "+currentPage*pageRecord+" ) where rownum > "+(currentPage -1)*pageRecord; 

第二页SQL演示:

select * from ( select rownum rn,t.* from addressbook where rownum<= 20 ) where rownum > 10

以上所述是小编给大家介绍的Oracle、MySQL和SqlServe三种数据库分页查询语句的区别介绍,希望对大家有所帮助!

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com