資料庫分頁技術

2021-05-21 18:46:47 字數 2298 閱讀 1187

1:無order by排序的寫法。(效率最高)

--(經過測試,此方法成本最低,只巢狀一層,速度最快!即使查詢的資料量再大,也幾乎不受影響,速度依然!)

select *

from (select rownum as rowno, t.*

from k_task t

where flight_date between to_date('20060501', 'yyyymmdd') and

to_date('20060731', 'yyyymmdd')

and rownum <= 20) table_alias

where table_alias.rowno >= 10;

--2:有order by排序的寫法。(效率最高)

--(經過測試,此方法隨著查詢範圍的擴大,速度也會越來越慢哦!)

select *

from (select tt.*, rownum as rowno

from (select t.*

from k_task t

where flight_date between to_date('20060501', 'yyyymmdd') and

to_date('20060531', 'yyyymmdd')

order by fact_up_time, flight_no) tt

where rownum <= 20) table_alias

where table_alias.rowno >= 10;

--3:無order by排序的寫法。(建議使用方法1代替)

--(此方法隨著查詢資料量的擴張,速度會越來越慢哦!)

select *

from (select rownum as rowno, t.*

from k_task t

where flight_date between to_date('20060501', 'yyyymmdd') and

to_date('20060731', 'yyyymmdd')) table_alias

where table_alias.rowno <= 20

and table_alias.rowno >= 10;

--table_alias.rowno  between 10 and 100;

--4:有order by排序的寫法.(建議使用方法2代替)

--(此方法隨著查詢範圍的擴大,速度會越來越慢哦!)

select *

from (select tt.*, rownum as rowno

from (select *

from k_task t

where flight_date between to_date('20060501', 'yyyymmdd') and

to_date('20060531', 'yyyymmdd')

order by fact_up_time, flight_no) tt) table_alias

where table_alias.rowno between 10 and 20;

--5另類語法。(有order by寫法)

--(語法風格與傳統的sql語法不同,不方便閱讀與理解,為規範與統一標準,不推薦使用。)

with partdata as(

select rownum as rowno, tt.*  from (select *

from k_task t

where flight_date between to_date('20060501', 'yyyymmdd') and

to_date('20060531', 'yyyymmdd')

order by fact_up_time, flight_no) tt

where rownum <= 20)

select * from partdata where rowno >= 10;

--6另類語法 。(無order by寫法)

with partdata as(

select rownum as rowno, t.*

from k_task t

where flight_date between to_date('20060501', 'yyyymmdd') and

to_date('20060531', 'yyyymmdd')

and rownum <= 20)

select * from partdata where rowno >= 10;   

SQL 資料庫分頁技術

分頁方案一 利用not in和select top分頁 語句形式 select top 10 from testtable where id not in select top 20 id from testtable order by id order by id select top 頁大小 f...

常用資料庫分頁技術

sql server資料庫 從資料庫表中的第m條記錄開始取n條記錄,利用top關鍵字 注意如果select語句中既有top,又有order by,則是從排序好的結果集中選擇 select from select top n from select top m n 1 from 表名稱 order b...

資料庫中的分頁技術

這個帖子很好,所以把內容記錄下來 oracle的分頁查詢語句基本上可以按照本文給出的格式來進行套用。分頁查詢格式 select from select a.rownum rn from select from table name a where rownum 40 where rn 21 其中最內...