怎么用sql语句查询第20条记录到第40条记录?

远程Scada 2003-10-23 10:21:43
如题!!
...全文
120 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
CrazyFor 2003-10-23
  • 打赏
  • 举报
回复
查询N-M条记录。
select IDENTITY(int,1,1) as iid,* into #temptable from yourtable
select top M-N * from #temptable where iid>=N

OR:

select top M-N * from yourTable where id not in(select top N-1 id from table)
ID为表具有唯一值的任何字段
wzh1215 2003-10-23
  • 打赏
  • 举报
回复
不对,应该是:
select * from tbl
where keyfld in
(select top 20 keyfld from tbl
where keyfld not in (select top 19 keyfld from tbl ))
WhyAndAnswer 2003-10-23
  • 打赏
  • 举报
回复
select * from tbl
where keyfld in
(select top 40 keyfld from tbl
where keyfld not in (select top 19 keyfld from tbl ))
这样行不行
lvltt 2003-10-23
  • 打赏
  • 举报
回复
select top 20 * from yourTable where id not in(select top 19 id from table)
lvltt 2003-10-23
  • 打赏
  • 举报
回复
查询N-M条记录。 select IDENTITY(int,1,1) as iid,* into #temptable from yourtable select top M-N * from #temptable where iid>=N OR: select top M-N * from yourTable where id not in(select top N-1 id from table) ID为表具有唯一值的任何字段

22,210

社区成员

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

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