求查询从第5条到第十条记录的SQL语句

likefg 2004-07-29 07:26:07
查询从第5条到第十条记录的SQL语句
...全文
239 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
futulove 2004-07-30
  • 打赏
  • 举报
回复
select top 5 * from (selecct top 10 * from tablename order by 主键 desc )
LYSSHE 2004-07-30
  • 打赏
  • 举报
回复
一楼的可以。
ruoyasoftware 2004-07-30
  • 打赏
  • 举报
回复
有主键当然好办,,如果没有主键的话,该怎么处理呢????
walkonthesky 2004-07-30
  • 打赏
  • 举报
回复
zjmym(缘木) 对的
小呆瓜错了
zheninchangjiang 2004-07-29
  • 打赏
  • 举报
回复
说错了,是一楼是比较好的方法,楼主也可以做一下测试
zheninchangjiang 2004-07-29
  • 打赏
  • 举报
回复
有ID,这是比较好的方法:
select * from [table] a where (select count(*) from [table] where id<=a.id) between 5 and 10 --不知效果如何

或者可以用临时表
select sn=identity(int,1,1),* into #t from [table]
select * from #t where sn between 5 and 10
likefg 2004-07-29
  • 打赏
  • 举报
回复
ZJMYM你写错了:应该是
select top 5 * from table where id not in(select top 10 id from table )
id 为主键
有其他的好方法吗
zjmym 2004-07-29
  • 打赏
  • 举报
回复
select top 5 * from table where id not in(select top 5 id from table )
id 为主键

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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