步步為營-46-分頁顯示的SQL語句
阿新 • • 發佈:2017-05-06
pid right user http play 技術分享 isp class 多少
說明:分頁顯示在實際業務中經常需要用到,其SQL語句分兩種
--方法一:跳過多少行,選中多少行 --每頁n條,選擇第m頁--n=2 m=3 --select top(n) * from 表 where 主鍵 not in (select top(m-1)*n 主鍵 from 表); select * from UserInfo select top(2) * from UserInfo where Empid not in (select top((3-1)*2) EmpId from UserInfo); --方法二,通過rowNumber函數,但是只能當作臨時表 select * fromView Code(select * ,ROW_NUMBER() over (order by EmpId) as num from UserInfo) as T where T.num between (3-1)*2+1 and 3*2; --over開窗函數的的另一個用法 select top(2) * ,AVG(StuAge) over() as 平均年齡 from UserInfo;
步步為營-46-分頁顯示的SQL語句