oralce sql 分页
create table student ( sid varchar2(10), --学号 sname varchar2(10), --姓名 classid varchar2(10), --班级号 score int --分数 );
insert into student values('001','z001','1',80); insert into student values('002','z001','1',90); insert into student values('003','z001','1',70); insert into student values('004','z001','1',90); insert into student values('005','z001','1',80); insert into student values('006','z001','1',70); insert into student values('007','z001','2',60); insert into student values('008','z001','2',70); insert into student values('009','z001','2',50); insert into student values('010','z001','2',70); insert into student values('011','z001','2',60); insert into student values('012','z001','2',50);
分页方法一: 用rownum 伪列进行分页:
SELECT t.* FROM (SELECT s.*,ROWNUM rn FROM student s WHERE ROWNUM <=9) t WHERE rn >= 8;
方法二:利用分析函数;
select * from (select t.*,row_number() over(order by SID desc) rk from student t) where rk<10 and rk>7;