高手请进:如何提取int类型的Field中的不连续的数值!

风中飘扬的柳絮 2003-04-09 04:45:06
table name : order_list
Field name : order_id int(4) not null

order_id 中存在有如下的资料:
——————————————————————————————————
order_id
___________
0
1
3
4
5
6
9
20
我如何用SQL来控制,提取缺少的编号,比如说:2,7,8,10,11等等....

高手,请指点
...全文
56 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-04-09
  • 打赏
  • 举报
回复
select top 100000 identity(int,1,1) id into # from sysobjects a,sysobjects b,sysobjects c

select * from # where id not in (select order_id from order_list)

drop table #
愉快的登山者 2003-04-09
  • 打赏
  • 举报
回复
create table #t(id int)
declare @mx int
declare @i int
select @mx = max(order_id) from order_list
set @i = 0
while @i <= @mx
begin
if not exists (select * from order_list where order_id = @i)
insert into #t (id) values (@i)
set @i = @i + 1
end
select * from #t
go

34,588

社区成员

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

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