不同資料庫oracle mysql SQL Server DB2 infomix sybase分頁查詢語句,infomixsybase

來源:互聯網
上載者:User

不同資料庫oracle mysql SQL Server DB2 infomix sybase分頁查詢語句,infomixsybase

在不同資料庫中的使用的分頁查詢語句:

當前頁:currentpage
頁大小:pagesize


1. Oracle資料庫

 select * from (select A.*,rownum rn from ( QUERY_SQL ) A )  where rn <= ((currentpage+1)*pagesize) and rn > (currentpage*pagesize)

註:QUERY_SQL為查詢sql語句。

select * from (select rownum rn,id from TABLENAME  where rownum <=((currentpage+1)*pagesize) ) A  where A.rn >= (currentpage*pagesize)

2. Infomix資料庫

select skip currentpage first pagesize * from TABLENAME
 
3. DB2資料庫

 select * from (select 欄位1,欄位2,欄位3,rownumber() over(order by 排序用的列名 asc) as RN from 表名) as A1 where A1.RN between (currentpage*pagesize) and ((currentpage+1)*pagesize) 
 或
 select * from (select rownumber() over(order by id asc ) as rowid from table where rowid <=((currentpage+1)*pagesize) )   where rowid > (currentpage*pagesize)
 
 
4. SQL Server資料庫

 select top pagesize *
  from TABLENAME
 where COLLUMN_NO not in
       (select top currentpage*pagesize COLLUMN_NO from TABLENAME order by COLLUMN_NO)
 order by COLLUMN_NO
 
5. Sybase資料庫

Sybase 12.5.3版本支援top查詢,或使用set rowcount N查詢頭N條資料
另外採用暫存資料表:
select rowid=identity(12), column_name into #TEMPTABLE from TABLENAME
select column_name  from #TEMPTABLE where rowid >(currentpage*pagesize) and rowid < (currentpage*pagesize+pagesize)

6. MySQL資料庫

 SELECT * FROM TABLE1 LIMIT (currentpage*pagesize),pagesize


Oracle,SQL_server,MySQL,DB2,Access,Sybase6個資料庫那個最適合下面的情況

SQL Server和MySQL夠用了,只不過ASP和ASP.NET語言要用前者,PHP和JSP語言要用後者。
 
小生新入門,可以不可以簡略的比較下oracle、SQL Server、DB2、sybase、mySQL五款主流資料系統優缺點,搞b/s的

如果是大型門戶網站多半用以下資料庫

oracle db2 sybase
可以建成關係複雜的資料倉儲

穩定 ,有專業維護 ,資料還易於分析
,一旦出了問題可以得到及時專業指導或災難恢複

小型的資料庫網站多辦用
mysql sqlserve
主要體積小
易學易用
 

相關文章

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.