mysql,sqlserver,oracle的分页语句

假设页数为pageNum,每页显示的记录数为pageSize;
MySQL的分页语句最简单:
select * from table_name limit (pageNum-1)*pageSize,pageNum*pageSize;
SQLServer的分页:
select top pageSize  *  from tabe_name where id not in (selec top (pageNum-1)*pageSize id from table_name);
其中的id必须保证在表中的值是唯一的,如果一个字段做不到,可以用多个字段联合起来,就跟联合主键类似。例如,我可以把id换成name,class两个字段,则语句改为:
select top pageSize * from tabe_name where name,class not in (selec top (pageNum-1)*pageSize name,class from table_name);

Oracle的分页:
第一种:select * from (select t.*,rownum from (select * from table_name) t where rownum <= pageNum*pageSize) where rownum >= (pageNum-1)*pageSize;
第二种:select * from (select t.*,rownum from (select * from table_name)) where rownum between (pageNum-1)*pageSize and pageNum*pageSize;
以上都是个人总结,时间仓促,有错误请提出,以免误人误己

你可能感兴趣的:(oracle,mysql)