CREATE TABLE #sample(id int identity ,weight float )insert into #sampleselect 10 union allselect 30 union allselect 20 union allselect 50.5 union allselect 100 union allselect 81 select * from #sample
id weight avg_current_prevoius 1 10 102 30 203 20 204 50.5 35.2500 5 100 67.2256 81 74.312500
;WITH tempavg AS (SELECT id, weight, weight avg_current_prevoius FROM #sample WHERE id = 1 UNION ALL SELECT a.id, a.weight, .5 * ( a.weight + b.avg_current_prevoius ) FROM #sample a INNER JOIN tempavg b ON b.id + 1 = a.id)SELECT *FROM tempavg;