oracle与mysql/fenye/ target=_blank class=infotextkey>mysql分页sql语句
一、oracle数据库分页查询语句
1.根据rowid来分
select * from t_xiaoxi where rowid in(select rid from (select rownum rn,rid from(select rowid rid,cid from
t_xiaoxi order by cid desc) where rownum<10000) where rn>9980) order by cid desc;
执行时间0.03秒
2.按分析函数来分
select * from (select t.*,row_number() over(order by cid desc) rk from t_xiaoxi t) where rk<10000 and rk>9980;
执行时间1.01秒
3.按rownum来分
select * from(select t.*,rownum rn from(select * from t_xiaoxi order by cid desc) t where rownum<10000) where rn>9980;执行时间0.1秒
二、mysql 分页sql语句
mysql中分页查询有两种方式, 一种是使用count(*)的方式:
select count(*) from foo where b = 1;
select a from foo where b = 1 limit 100,10;
方法二,使用sql_calc_found_rows
select sql_calc_found_rows a from foo where b = 1 limit 100, 10;
select found_rows();
注意,sql_calc_found_rows和count(*)的性能在都使用covering index的情况下前者高,在没使用covering index情况下后者性能高。