I have a table like this in mysql where only three field id,credit and debit exists now i want to calculate the current balance as like below in examp column i show how i want mysql to calculate it will search for just previous time current balance. table is ordered by time.....
id credit debit Time balance Examp
1 100 1/6/2013 11:11 100
1 50 1/6/2013 13:14 50 (100-50)
1 20 2/6/2013 10:10 70 (50+20)
2 200 1/6/2013 11:12 200
2 100 1/6/2013 11:14 300 (200 + 100)
2 150 2/6/2013 10:10 150 (300 -150)