高分求助,在SQLServer2000里,用一条SQL语句实现取查询结果的第n条到第m条记录?

lovecure 2003-08-12 08:23:39
如:
select a.*,b.* from plm_user as a,plm_permit as b
where a.code=b.usercode

我想取其结果的第10条至第20条,该怎样写?
...全文
43 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovecure 2003-08-13
  • 打赏
  • 举报
回复
终于搞定了,

select top 10 * from plm_permit inner join plm_user on plm_user.code=plm_permit.usercode
where plm_permit.id not in (select top 200 ID from plm_permit)

还是要谢谢大家了!
pengdali 2003-08-12
  • 打赏
  • 举报
回复
declare @SQLStr varchar(8000)
set @SQLStr='SELECT Top '+cast(@每页大小 as varchar)+' * FROM 表 WHERE 主键列 NOT IN (SELECT TOP '+cast(@每页大小*@第几页 as varchar)+' 主键列 from 表 )'
exec(@SQLStr)
qianguob 2003-08-12
  • 打赏
  • 举报
回复
高,学习。
zjcxc 元老 2003-08-12
  • 打赏
  • 举报
回复
如果没有的话,就用临时表才行:

select top 20 myid=identity(int,1,1),* into #tb from(select a.*,b.* from plm_user as a,plm_permit as b
where a.code=b.usercode) a

select * from #tb where between 10 and 20

drop table #tb

zjcxc 元老 2003-08-12
  • 打赏
  • 举报
回复
你的表有主键吗,有的话就可以用一条语句查出

select top 10 * from (select a.*,b.* from plm_user as a,plm_permit as b
where a.code=b.usercode) a where 主键 not in(select top 10 主键 from (select a.*,b.* from plm_user as a,plm_permit as b
where a.code=b.usercode
)a)
txlicenhe 2003-08-12
  • 打赏
  • 举报
回复
Select identity(int,1,1) as id,a.*,b.* into #tmp
from plm_user as a,plm_permit as b
where a.code=b.usercode

Select * from #tmp where id between 10 and 20
drop table #tmp

34,588

社区成员

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

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