日期:2014-05-16  浏览次数:20905 次

MySQL 分页sql语句练习
[/align][align=left]
取出sql表中第31到40的记录(以自动增长ID为主键)

select top 10  * from t where id not in (select top 30 id from t order by id ) order by id;

select top 10 * from t where id in (select top 40 id from t order by id ) order by id desc ;

mysql方案:select * from t order by id limit 30,10;

以以上语句为基础设计分页sql语句(直接利用sql语句进行分页,效率最高)
String sql = "select * from t limit"+(pageNo-1)*pageSize+","+pageSize;
select * from t limit (pageNo-1)*pageSize , pageSize;

oracle: sql = "select * from " +
"(select rownum r,* from " +
"(select * from articles order by postime desc)" +
"where rownum<= " + pageNo*pageSize +") tmp " +
"where r>" + (pageNo-1)*pageSize;