sql: running total

by prettyscripts on 2011-10-28 10:35

sql

to calculate running total / balance in a single sql statment, eg:

Code:

select    a.id,
          a.quantity,
         (select sum(b.quantity)
          from stock b
          where b.id <= a.id) as running_total
from stock a
;