如何实现分页操作?
page 当前页数 1
rows 当前显示条数 5
【page:1,rows:5】 1-5
【page:2,rows:5】 6-10
【page:3,rows:5】 11-15
开始位置 :1+((页数-1)*条数)
结束位置:条数*页数
分页语句怎么写呢?
错误语句:
因为是根据新闻id来做判断的,如果数据删除,界面就会没有数据
查第1~5条
select * from t_news where news_id between 1 and 5;
查第6~10条
select * t_news where news_id between 6 and 10;
正确语句:
根据列的顺序,伪列:rownum,如果删除一行会自动把序号补上
select a.*,rownum from t_news a;
查第1~5条
select a.* from _news a where rownum between 1 and 5;
但是查6~10条会发现没有数据,那我们得说一下伪列rownum的特性 :
不能用于大于1,
伪列是先搞好,再排序的
我们可以将伪列变成实列
select * from(
select a.*,rownum myr from t_news a where news_title like '%%'
)b where myr between 6 and 10