在十多万的表中进行那样的操作,还是tanghuan的速度快些。
还可有一点优化
execute("create table #temptable (RowNum int identity,数据列)
insert #temptable (数据列)
select top torownum 数据列
from .....
select 数据列
from #temptable
where RowNum between fromrownum and to torownum
")
execute("create table #temptable (RowNum int identity,数据列)
insert #temptable (数据列)
select 数据列
from .....
select 数据列
from #temptable
where RowNum between fromrownum and to torownum
")
假设有一员工表Employee(EmployeeID,EmployeeName,...),
要返回第10条至第20条之间的记录,可用如下语句:
select * from employee
where (EmployeeID not in ( select top 10 EmployeeID from employee))
and (EmployeeID in (select top 20 EmployeeID from employee))
1、Select Top 5 From Hello 返回前五条记录
Select Top 10 PERCENT From Hello 返回10%的记录
Limiting Result Sets Using TOP and PERCENT
The TOP clause limits the number of rows returned in the result set.
TOP n [PERCENT]
n specifies how many rows are returned. If PERCENT is not specified, n is the number of rows to return. If PERCENT is specified, n is the percentage of the result set rows to return:
TOP 120 /*Return the top 120 rows of the result set. */
TOP 15 PERCENT /* Return the top 15% of the result set. */.