先来定义分页语句将要用到的几个参数:
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
以上所述是www.887551.com给大家介绍的oracle、mysql和sqlserve三种数据库分页查询语句的区别介绍,希望对大家有所帮助!