使用mysql select query中的另一个字段添加或减去字段值

I want to get carry forward a field value using another field

This is my table transaction

------------------------------
id   | amount  | is_income    |
------------------------------
1    | 400     |1
2    | 100     |0
3    | 300     |1

I want to get the result like

--------------------------------------
id   | amount  | is_income |Balance  |
--------------------------------------
1    | 400     |1          | 400
2    | 100     |0          | 300
3    | 300     |1          | 600

If is_income field is 1 then add amount with previous amount. and if is_income field is 0 then subtract with previous amount.

if any method to get result without stored procedure ?

Try this:

SET @balance = 0;
SELECT * , IF( is_income =1, @balance := @balance + amount, @balance := @balance - amount ) AS balance FROM  `your table name `