怎样控制SQL SERVER返回的记录数???

small_wolf 2000-03-23 09:02:00
比如建立一个查询,我想返回SELECT * FROM TABLE 结果集的第100到第150条记录
如果不用游标能否实现
...全文
429 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
small_wolf 2000-05-19
  • 打赏
  • 举报
回复
谢谢大家的讨论。
Axiong 2000-04-20
  • 打赏
  • 举报
回复
在十多万的表中进行那样的操作,还是tanghuan的速度快些。
还可有一点优化
execute("create table #temptable (RowNum int identity,数据列)
insert #temptable (数据列)
select top torownum 数据列
from .....
select 数据列
from #temptable
where RowNum between fromrownum and to torownum
")
tanghuan 2000-03-30
  • 打赏
  • 举报
回复
如果你使用的是MSSQL,用一下方法可以

execute("create table #temptable (RowNum int identity,数据列)
insert #temptable (数据列)
select 数据列
from .....
select 数据列
from #temptable
where RowNum between fromrownum and to torownum
")
small_wolf 2000-03-28
  • 打赏
  • 举报
回复
用游标就更慢了
zdg 2000-03-27
  • 打赏
  • 举报
回复
Select Top 语法只对Access和SQL Server 7.0才能用...
SQL Server 6.5不能使用...
为什么不用游标呢???
hardnut 2000-03-27
  • 打赏
  • 举报
回复
是否可以考虑对表进行水平划分,把其中常用的20%与几乎不用的80%分别放在两个表中,
<<Microsoft sql server 6.5开发指南>>上说了这个问题,但也只是‘点到为止’
small_wolf 2000-03-27
  • 打赏
  • 举报
回复
能不能有效率更高,执行速度更快的方法了,用IN命令执行速度太慢了(记录大概有十万条)。尽管我加了ID为簇索引。
How 2000-03-25
  • 打赏
  • 举报
回复
假设有一员工表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))
Tony_Yuan 2000-03-24
  • 打赏
  • 举报
回复
select * from table_1 where table_1.id in (select top 150 id from table_1)
and table_1.id not in (select top 100 id from table_1)
small_wolf 2000-03-24
  • 打赏
  • 举报
回复
能否返回中间的结果集。比如我想返回SELECT * FROM TABLE 结果集的第100到第150条记录
weyoung 2000-03-23
  • 打赏
  • 举报
回复
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. */.
King 2000-03-23
  • 打赏
  • 举报
回复
可以用Set RowCount n(n是整数,0的话就返回所有记录)来限定返回的记录数。也可以用Select top n 来实现(这个方法我老是失败,得请教高手了:)。

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧