rownum为虚拟列,不是实际物理列

select rownum,t.code from sys_config t; // 取得行数和code列

select rownum, t.code from sys_config t where rownum <=20 order by t.code; // 取得行数<=20,并按code排序,排序失败

select rownum, code from (select * from sys_config order by code) where rownum <=20; // 取得前20行成功

select rownum, code from (select * from sys_config order by code) where rownum>=1 and rownum <=20; // 取得1到20行成功

select rownum, code from (select * from sys_config order by code) where rownum>=2 and rownum <=20; // 取得2到20行失败

select rn,code from (select rownum as rn,code from (select * from sys_config order by code)) where rn >=2 and rn <=20; // 取得2到20行成功

最后一行为分页查询SQL语句,其他分页语句:
select * from (select rownum as rn, T.* from (select * from table_name) T where rownum<40) where rn>21; // 效率高些
select * from (select rownum as rn, T.* from (select * from table_name) T) where rn between 20 and 40; // 效率低些

参考连接文章:

http://database.51cto.com/art/201106/270156.htm

http://database.51cto.com/art/200904/118737.htm

相关文章:

  • 2021-12-22
  • 2021-11-18
  • 2021-06-26
  • 2021-05-27
  • 2021-10-15
  • 2021-11-10
猜你喜欢
  • 2021-09-04
  • 2022-12-23
  • 2022-01-15
  • 2021-07-09
  • 2021-08-09
  • 2022-02-01
相关资源
相似解决方案