sql server 2000中查询中间记录的问题

来源:百度知道 编辑:UC知道 时间:2024/05/26 18:22:22
各位
有对Sql server 2000比较熟悉的帮下我

你觉得一条纯SQL语句能查询一个表中的中间10条记录吗?
标识字段:ID,但是ID有可能不连续,比如1、2、4、6
记录总数不定
--------------------------------
谢谢了
1楼的,如果我知道那是第几行开始的。就好了。关键是不知道。
总数也不知道。

给你来个nb的呵呵
select top 10
(select abs(count(*)-(select count(*) from tabletest)/2+1.5) from tabletest where id<A.id) as oid,
*
from tabletest A order by 1

只要知道那是第几条开始的就行,比如知道那是第12条,就是说查找从第12条记录开始的后面10条记录
select top 10 * from 表名 where ID not in (select top 11 ID from 表名)

declare @n as integer
select @n= count(*)/2 from 表名
exec ('select top 10 * from 表名 where ID not in (select top'+ convert(char(20),@n)+' ID from 表名)')

那查什么10条记录呢?
select * from 表
where id in(select top 100 id from 表 order by id)
and id not in(select top 90 id from 表 order by id)

declare @c int
select @c=(count(*)-10)/2 from 表
select top 10 * from 表 where id not in (select top (@c) id from 表 order by id) order by id