sql server 2000中,有2个字段为主键的表,怎样分页?

lokii 2007-04-18 10:39:14
K1为主键,第3页可以这样查
select top 10 * from tab1
where K1 not in
(
select top 10*(3-1) K1 from tab1
order by K1
)
order by K1

要是主键是(K1,K2)呢?
...全文
192 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainlovesea 2008-07-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zjcxc 的回复:]
sql 2005可以直接用rownumber函数

select * from(
select rid = row_number() over(order by k1, k2),*
from tab1
)a
where rid between 31 and 40
[/Quote]

钻石的,
tianhuo_soft 2008-07-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 hery2002 的回复:]
..
[/Quote]
格拉 2008-07-24
  • 打赏
  • 举报
回复
看到四个钻石!
hery2002 2008-07-24
  • 打赏
  • 举报
回复
..
zjcxc 2007-04-18
  • 打赏
  • 举报
回复
sql 2005可以直接用rownumber函数

select * from(
select rid = row_number() over(order by k1, k2),*
from tab1
)a
where rid between 31 and 40
撸大湿 2007-04-18
  • 打赏
  • 举报
回复
declare @sqlstr nvarchar(4000), --查询字符串
@pagecount int,--第N页
@pagesize int--每页行数
select @pagecount=3--第3页
,@pagesize=10--第页10条
,@sqlstr='select * from sysobjects'
set nocount on
declare @P1 int,--P1是游标的id
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select @rowcount as 总行数,ceiling(1.0*@rowcount/@pagesize) as 页数,@pagecount as 当前页
set @pagecount=(@pagecount-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@pagecount,@pagesize
exec sp_cursorclose @P1



现在流行这个

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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