标签:
方法1: 适用于 SQL Server 2000/2005/2008
SELECT TOP 10 *
FROM YieldRole
WHERE id NOT IN
(
SELECT TOP (10*(1-1)) id FROM YieldRole ORDER BY id
)
ORDER BY id
方法2: 适用于 SQL Server 2000/2005/2008
--顺序写法:
SELECT TOP 10 *
FROM YieldRole
WHERE id >=
(
SELECT ISNULL(MAX(id),0)
FROM
(
SELECT TOP (10*(2-1)+1) id FROM YieldRole ORDER BY id
) A
)
ORDER BY id
--降序写法:
SELECT TOP 10 *
FROM YieldRole
WHERE id <=
(
SELECT ISNULL(MIN(id),0)
FROM
(
SELECT TOP (10*(2-1)+1) id FROM YieldRole ORDER BY id Desc
) A
)
ORDER BY id Desc
方法3: 适用于 SQL Server 2000/2005/2008
SELECT TOP 10 *
FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNumber,* FROM YieldRole
) A
WHERE RowNumber > 10*(2-1)
通过SQL 查询分析器,显示比较:我的结论是:
分页方案二:(利用ID大于多少和SELECT TOP分页)效率最高,需要拼接SQL语句
分页方案一:(利用Not In和SELECT TOP分页) 效率次之,需要拼接SQL语句
分页方案三:(利用SQL的游标存储过程分页) 效率最差,但是最为通用
标签:
原文地址:http://www.cnblogs.com/FKdelphi/p/4640594.html