请问如何用查询语句取出从第n1条到第n2条中的记录?

myepoch 2005-01-27 08:36:31
如何用查询语句取出从第n1条到第n2条中的记录?
...全文
159 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
---涛声依旧--- 2005-01-27
  • 打赏
  • 举报
回复
如果有關鍵字段的話
select * from (select top n2 * from 表 ) a
where 關鍵字段 not in(select top n1 關鍵字段 from 表)

如果沒有,可以用临时表,加标识字段解决

select id=identity(int,1,1),* into #tb from 表
select * from #tb where id between n1 and n2
---涛声依旧--- 2005-01-27
  • 打赏
  • 举报
回复
to :Qihua_wu(小吴)
你那樣用會出錯﹐inditity 只能用于Select * into 表 的形式
Softlee81307 2005-01-27
  • 打赏
  • 举报
回复
或者用#表
select *,identity(int,1,1) as p into #a from 表
---------再查表#a
select * from #a where p between n1 and n2
yyyjff 2005-01-27
  • 打赏
  • 举报
回复
select top n2-n1 from (select top n2 * from 表 ) a
where 關鍵字段 not in(select top n1 關鍵字段 from 表)
Qihua_wu 2005-01-27
  • 打赏
  • 举报
回复
select inditity(int,0,1) as id,a.* from a where condition
select * from id >= ? and id<=?
myepoch 2005-01-27
  • 打赏
  • 举报
回复
to Softlee81307(孔腎) 多谢。

请问还有更好的方法吗?
Softlee81307 2005-01-27
  • 打赏
  • 举报
回复
如果有關鍵字段的話
select * from (select top n2 * from 表 ) a
where 關鍵字段 not in(select top n1 關鍵字段 from 表)

---------就行了
iming 2005-01-27
  • 打赏
  • 举报
回复
MySql有此功能,很方便数据分页的,可惜呀MS Sql!

34,576

社区成员

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

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