mysql> SELECT * FROM table LIMIT 5,10; // 检索记录行 6-15
//为了检索从某一个偏移量到记录集的结束所有的记录行,可以指定第二个参数为 -1:
mysql> SELECT * FROM table LIMIT 95,-1; // 检索记录行 96-last.
//如果只给定一个参数,它表示返回最大的记录行数目:
mysql> SELECT * FROM table LIMIT 5; //检索前 5 个记录行
//换句话说,LIMIT n 等价于 LIMIT 0,n。
MSSQL实现方式
SELECT * FROM
(
SELECT TOP [每页记录] * FROM
(
SELECT TOP [每页记录*当前页数] [字段1, 字段2, ...]
FROM [数据表]
ORDER BY [排序字段] DESC
)
[表别名1]
ORDER BY [排序字段]
)
[表别名2]
ORDER BY [排序字段] DESC
SELECT * FROM
(
SELECT TOP 5 * FROM
(
SELECT TOP 20 *
FROM t_base_City
ORDER BY Fid DESC
) t1
ORDER BY Fid asc
) t2
ORDER BY Fid DESC
declare @sqlstr nvarchar(4000), --查询字符串
@pagecount int, --第N页
@pagesize int --每页行数
select @pagecount=3,@pagesize=10
,@sqlstr='select * from sysobjects'
set nocount on
declare @P1 int, --P1是游标的id
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select @rowcount as 总行数,ceiling(1.0*@rowcount/@pagesize) as 页数,@pagecount as 当前页
set @pagecount=(@pagecount-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@pagecount,@pagesize
exec sp_cursorclose @P1