27,579
社区成员
发帖
与我相关
我的任务
分享
declare @t table(fID decimal(10,0)
,fValue decimal(18,0)
,fTotal decimal(18,0)
)
declare @bID decimal(10,0)
,@bCount decimal(10,0)
set @bCount =1500
set @bID=1
while @bID<=@bCount
begin
insert into @t (fID ,fValue )
select @bID,@bID
select @bID+=1
end
select * from @t
--求此处的高效更新语句
update @t set fTotal =v2.fValue
from @t v1
left join (select a.fID,fValue=SUM (b.fValue) from @t a
left join @t b on a.fID >=b.fID
group by a.fID) v2 on v1.fID =v2.fID
select * from @t
declare @tmp int
set @tmp=0
update @t
set @tmp=@tmp+fValue,fTotal=@tmp