Oracle数据库
SELECT
*
FROM
(
SELECT
ROWNUM AS NO_ROW
,row_.*
FROM
(
SELECT
*
FROM
PLAN_TEMP
) row_
)
WHERE
NO_ROW BETWEEN 1 AND 12
PostgreSQL
select * from table limit 1 offset 12;
MySQL
select * from table limit 1, 12
SQL Server
select top 12 * from table
分页:
1.Oracle
SELECT
*
FROM (
SELECT
row_.*, rownum rownum_
FROM
(...... ) row_
WHERE
rownum <= ?)
WHERE rownum_ > ?
先按查询条件查询出从0 到页未的记录.然后再取出从页开始到页未的记录.(据说是效率最高的:))
2. SQL Server
i:select top [pagesize] *
from table
where
id not in (
select top [pagesize*(currentpage-1)] id
from table
[查询条件] order by id )
and [查询条件] order by id
先按查询条件排除 pagesize*[pagesize* (currentpage-1)]以前的纪录。&&再按查询条件把他以后的记录 top[pagesize] 出 来.
ii: select top PageSize *
from TableName
where id > (
select max(id)
from
(select top startRecord-1 id
from TableName
[查询条件]
order by id) as TempTable)
[查询条件]
order by id )
先取得开始该页开始时的最大ID,然后再 从最大ID出top[pagesize] (听说记录组超过10万第二条好过第一条)
3.MySQL select * from table [查询条件] order by id limit ?,?
4.PostgreSQL:
select * from table order by id group by id limit ? offset ?