如何取出这些数据?

zzmsl 2006-08-06 04:49:46
已知有一列数据共15条,他们的主键是ID,自动增长1,ID可能是不连续的,例如:

ID
1
2
3
7
8

9
10
11
12
18

19
20
22
24
30

求一SQL语句,要求:直接取出这些数据中的第N至M条,例如取第5-10条,即是
ID
9
10
11
12
18
...全文
130 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangxiaopin 2006-08-06
  • 打赏
  • 举报
回复
SELECT * FROM YOURTABLENAME WHERE ID IN(9,10,18)
zhangxiaopin 2006-08-06
  • 打赏
  • 举报
回复
SELECT * FROM YOURTABLENAME WHERE ID>=6 AND ID<=10
九斤半 2006-08-06
  • 打赏
  • 举报
回复
create table test
(ID int)
insert test (id)
select 1 union all
select 2 union all
select 3 union all
select 7 union all
select 8 union all

select 9 union all
select 10 union all
select 11 union all
select 12 union all
select 18 union all

select 19 union all
select 20 union all
select 22 union all
select 24 union all
select 30

--select * from test

--求一SQL语句,要求:直接取出这些数据中的第N至M条,例如取第5-10条,即是
select top 6 * from test where id not in(select top 5 id from test)

drop table test

22,294

社区成员

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

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