SQL结果集累加

if OBJECT_ID('tempdb..#linshi') is not null

drop table #linshi

SELECT id=identity(int,1,1), Cost

into #linshi

FROM XXXX
Order By Cost Desc select * ,count=( select sum(Cost) from linshi i where i.id<o.id ) from #linshi o

  

你可能感兴趣的:(sql)