主键是什么啊?如果主键是ID + number列的话:
declare @ID INT, @number INT
create table #T_ID( ID INT )
create table #TI ( number int, cellid int )
inset #T_ID select distinct ID from 原表 order by 1
while ( select count(*) from #T_ID ) > 0
select top 1 @ID = ID from #T_ID
delete #T_ID WHERE @ID = ID
delete #T1
inset #T1 select number, cellID from 原表 where ID = @ID
while ( select count(*) from #T1 ) > 0
begin
select top 1 @number = number from #T1
delete #T1 WHERE @number = number
insert 新表
select @ID, @number, cellID, @number - isnull( ( select top 1 number from 原表 where ID = @ID and number < @number order by number ), @number )
FROM 原表 where ID = @ID and @number = number
end
end
你这不是写出来了么?
numberinterval=select * from nub2-nub1
哦,原来ID是个线程,哈哈那这个可复杂了!
你给的分少,我可不答!
纯SQL完成我也不会,关注一下。
郁闷的是,没有一个标识列。
貌似还要按ID分组计算