SQL分頁語句格式

使用between分頁的,要用rownumber,因爲要防止有些id不存在
pagesize=10
pageindex start end
1頁 1 10
2頁 11 20
3頁 21 30



pageindex          start=(pageindex-1)*10+1     end=pageindex*pagesize


select * from(select row_number() over(order by id) as num,* from tblname) as tbl
where num between start and end






使用top分頁
pagesize=10
1頁 select top 10 * from tblname where id not in(select top 0 id from tblname)
2頁 select top 10 * from tblname where id not in(select top 10 id from tblname)
3頁 select top 10 * from tblname where id not in(select top 20 id from tblname)
n頁 select top pagesize * from tblname where id not in(select top (n-1)*pagesize id from tblname)
發佈了32 篇原創文章 · 獲贊 7 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章