假设有一个表只有书名和作者,一共有10行,那求第五到第十行的书名和作者,除了用minus外,即(
select rownum ,title,author from where rownum<11
minus
select rownum,title,author from where rownum>5;
)
请问用sql语句子查询怎么写?
select rownum ,title,author from where rownum<11
minus
select rownum,title,author from where rownum>5;
)
请问用sql语句子查询怎么写?
from
(select a.*,row_number() over(order by title) rn
from tb a
)
where rn between 5 and 10
;
,第1条不大于5则排除,查第二条,因此... where rownum>5;是没数据的
方法一:
select *
from
(select a.*,row_number() over( order by title) rn
from tb a
)
where rn between 5 and 10
方法二:
select * from (select a.*,rownum as numbers from tb a where a.rownum<=10) b where b.rownum>=6;
SELECT * FROM
(
SELECT A.*, ROWNUM RN
FROM (SELECT * FROM TABLE_NAME) A
WHERE ROWNUM <= 40
)
WHERE RN >= 21
其中最内层的查询SELECT * FROM TABLE_NAME表示不进行翻页的原始查询语句。ROWNUM <= 40和RN >= 21控制分页查询的每页的范围。