怎么写select可以得到某几条符合规则的记录

idoloveyou 2003-10-15 05:42:39
怎么写select可以得到某几条符合规则的记录
比如我想得到第5-8条记录,怎么写?
...全文
94 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gmlxf 2003-10-15
  • 打赏
  • 举报
回复
5-8这4条记录(降序)
select top 4 * from
(select top 8 * from 表 order by id) a
order by id desc

5-8这4条记录(升序)
select * from
(
select top 4 * from
(select top 8 * from 表 order by id) a
order by id desc
) a
order by id
gmlxf 2003-10-15
  • 打赏
  • 举报
回复

5-8这4条记录(降序)
select top 4 * from
(select top 8 * from 表 order by id) a
order by iddesc

5-8这4条记录(升序)
select * from
(
select top 4 * from
(select top 8 * from 表 order by id) a
order by id desc
) a
order by id
idoloveyou 2003-10-15
  • 打赏
  • 举报
回复
子查询最多能返回一个记录
yujohny 2003-10-15
  • 打赏
  • 举报
回复
ID是表的主键
select top 4 * from 表 where id= (select top 8 from 表 order by id)
order by id desc
yujohny 2003-10-15
  • 打赏
  • 举报
回复
select top 4 from 表 where id= (select top 8 from 表 order by id)
order by id desc
pengdali 2003-10-15
  • 打赏
  • 举报
回复
select IDENTITY(int, 1,1) AS ID_Num,* into #temp from 表
select * from #temp where ID_Num between 10 and 20

34,575

社区成员

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

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