数据库下的分页代码

最近一段时间都在搞复习,没办法,得面试找工作...在数据库方面还是有点薄弱,得好好复习一下才行,下面是三种常用的数据库的分页sql:

sql server:

 String sql =

       "select top " + pageSize + " * from students where id not in" +

 "(select top " + pageSize * (pageNumber-1) + " id from students order by id)" +"order by id"; 

mysql: 

  String sql =

       "select * from students order by id limit " + pageSize*(pageNumber-1) + "," + pageSize; 

oracle:  

 String sql =  "select * from " +  
(select *,rownum rid from (select * from students order by postime desc) where rid<=" +
        pagesize*pagenumber + ") as t" + "where t>" + pageSize*(pageNumber-1);   

你可能感兴趣的:(数据库下的分页代码)