人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動態(tài)

基于sqlserver的四種分頁方式總結(jié)

發(fā)布日期:2021-12-12 15:10 | 文章來源:站長之家

第一種:ROW_NUMBER() OVER()方式

select * from (
    select *, ROW_NUMBER() OVER(Order by ArtistId ) AS RowId from ArtistModels
  ) as b

where RowId between 10 and 20

---where RowId BETWEEN 當前頁數(shù)-1*條數(shù) and 頁數(shù)*條數(shù)---

執(zhí)行結(jié)果是:

第二種方式:offset fetch next方式(SQL2012以上的版本才支持:推薦使用 )

select * from ArtistModels order by ArtistId offset 4 rows fetch next 5 rows only
--order by ArtistId offset 頁數(shù) rows fetch next 條數(shù) rows only ----

執(zhí)行結(jié)果是:

第三種方式:--top not in方式 (適應于數(shù)據(jù)庫2012以下的版本)

select top 3 * from ArtistModels
where ArtistId not in (select top 15 ArtistId from ArtistModels)

------whereIdnotin(selecttop條數(shù)*頁數(shù) ArtistIdfrom ArtistModels)

執(zhí)行結(jié)果:

第四種方式:用存儲過程的方式進行分頁

CREATE procedure page_Demo
@tablename varchar(20),
@pageSize int,
@page int
AS
declare @newspage int,
@res varchar(100)
begin
set @newspage=@pageSize*(@page - 1)
set @res='select * from ' +@tablename+ ' order by ArtistId offset '+CAST(@newspage as varchar(10)) +' rows fetch next '+ CAST(@pageSize as varchar(10)) +' rows only'
exec(@res)
end
EXEC page_Demo @tablename='ArtistModels',@pageSize=3,@page=5

執(zhí)行結(jié)果:

ps:今天搞了一下午的分頁,通過上網(wǎng)查資料和自己的實驗,總結(jié)了四種分頁方式供大家參考,有問題大家一起交流學習。

版權聲明:本站文章來源標注為YINGSOO的內(nèi)容版權均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務

7x24全年不間斷在線

專屬顧問服務

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務熱線

關注
微信

關注官方微信
頂部