update table set totalprice=TA.total
from table
join (
select id,member,Sum(B.volume) as total
from table A
left join table B on A.member=B.member and B.id between A.id-n and A.id
group by id,member
) as TA on table.id=TA.id and table.member=TA.membe