Oracle、MySQL和SQL Serve分頁查詢的語句區別

來源:互聯網
上載者:User

Oracle、MySQL和SQL Serve分頁查詢的語句區別

★先來定義分頁語句將要用到的幾個參數:

int currentPage ; //當前頁
int pageRecord ; //每頁顯示記錄數
以之前的ADDRESSBOOK資料表為例(每頁顯示10條記錄):

一、SqlServe下載 分頁語句

String sql = "select top "+pageRecord +" * from addressbook where id not in (select top "+(currentPage-1)*pageRecord +" id from t_user)"; 
// (currentPage-1)*pageRecord : 是指從第幾個記錄開始 

第二頁SQL示範:

select top 20 * from addressbook where id not in (select top 10 id from addressbook)

二、MySQL資料庫分頁語句

String sql = "select * from addressbook where limit "+(currentPage-1)*pageRecord +","+pageRecord +""; 
         
//select * from 表名 【條件】limit M,N;   
//M為從第幾個記錄開始,比如每頁顯示3條記錄,第二頁就必須從第4條記錄開始 
//N每頁讀幾個資料 

第二頁SQL示範:

select * from addressbook where limit 10,10

三、Oracle資料庫分頁語句

String sqls = "select * from ( select rownum rn,t.* from addressbook t where rownum <= "+currentPage*pageRecord+" ) where rownum > "+(currentPage -1)*pageRecord; 
         
第二頁SQL示範:

select * from ( select rownum rn,t.* from addressbook where rownum<= 20 ) where rownum > 10

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.