sql server - how to add the value of the next row within a group in sql -
how can result column?
p_key staff amt emi result 372175 9174 1584 1 1584 372176 9174 1619 2 3203 372177 9174 1654 3 4857 372178 9174 1689 4 6546 372179 9174 1726 5 8272 699334 22057 1136 1 1136 699335 22057 1161 2 2297 699336 22057 1186 3 3483 699337 22057 1212 4 4695 699338 22057 1238 5 5933 699339 22057 1265 6 7198 699340 22057 1292 7 8490 699341 22057 1320 8 9810 699342 22057 1349 9 11159
you seem want cumulative sum. in sql server 2008, 1 method apply
:
select t.*, t2.result t cross apply (select sum(amt) result t2 t2.staff = t.staff , t2.emi <= t.emi ) t2;
Comments
Post a Comment