sql 排序分頁

2021-08-08 20:35:02 字數 860 閱讀 8384

本文介紹oracle/sqlserver資料庫分頁

oracle 分頁

1.1 使用偽列 rownum 大家常說的三層巢狀,如下:  

--三層巢狀,缺一不可

select * from (

select rownum as rn,b.* from (

select t.pos_code,t.zh_title from proposal t where t.pos_code is

notnull

order

by t.pos_code)b

where rownum<500)c

where c.rn >=400;

結果

1.2 使用分析函式row_number() over(order by ….) as rn

注:這個函式在sqlserver中的語法也是這樣的.

select * from (

select row_number()over(order

by t.pos_code asc) as rn,t.pos_code,t.psn_code from proposal t)a

where a.rn >400

and a.rn<=500;

結果

SQL語句基礎(排序,分頁)

desc 降序排序 asc 公升序排序 資料庫表主鍵如果是遞增預設就是公升序,一般都是這樣的 limit後面可以帶乙個值或者兩個值 乙個值 limit n就是返回從開始公升序查詢到的n條資料 兩個值 limit m,n 表示從m位置開始取n條資料,第乙個值表示開始位置,第二個值表示多少條資料。例子 ...

oracle 排序分頁 高效sql語句

最好還是利用分析函式row number over partition by col1 order by col2 比如想取出100 150條記錄,按照tname排序 select tname,tabtype from select tname,tabtype,row number over ord...

oracle排序並分頁sql語句

因為oracle沒有mysql的limit的語法,因此排序和分頁不能方便的完成,但是通過三次巢狀查詢可以達到同樣的功能 selecttemp2.from select rownum num,temp1.from select fields we want from table order by fi...