select *
from ( select rownum as rowno, t.*
from table t where rownum <= page*size) table_aliaswhere table_alias.rowno > (page-1)*size;
有order by语句的分页:select *
from ( select rownum as rowno,r.*
from( select * from table t
order by t.element asc
) r
where rownum <= page*size
) table_alias
where table_alias.rowno > (page-1)*size;
上限条件必须放在子查询,而下限条件必须放在外层查询 (rownum总是从1开始的,第一条不满足去掉的话,第二条的rownum 又成了1)。
顺便提一下 :mysql中分页查询sql格式是:select * from table limit m,n;
其中m是每页起始页码,n是每页显示的条数,m =( pagenum – 1) *n