1. 程式人生 > >資料庫分頁詳解

資料庫分頁詳解

作用:加快資料檢索速率

greenplum/postgres分頁語法

select [*|欄位列表] from table_name where expresion [limit {count|all}] [offset start]; 
--limit:指定select結果的顯示條數
--offset:指定資料檢索的起始位置

MySQL分頁語法

select [*|欄位列表] from table_name where expresion limit m,n;
--m:資料檢索的其實位置
--n:每頁顯示的資料條數

SQLServer分頁語法

--方式一
select top pageSize * from 表名 where id  not in (select top pages id from 表名 order by id) order by id 
--方式二
 select top pageSize * from 表名 where id>=(select max(id) from (select top pages id from 表名 order by id asc ) t )
--pageSize:每頁顯示的資料條數

Oracle/DB2分頁語法

select [*|欄位列表] from table_name where 欄位>=startPage and 欄位<endPage;
--startPage:起始位置
--pageSize:每頁顯示的資料數
--endPage:startPage+pageSize