balance

Calculate balance with mysql

為{幸葍}努か 提交于 2019-11-27 13:21:00
问题 I have a table which contains the following data: ID In Out 1 100.00 0.00 2 10.00 0.00 3 0.00 70.00 4 5.00 0.00 5 0.00 60.00 6 20.00 0.00 Now I need a query which gives me the following result: ID In Out Balance 1 100.00 0.00 100.00 2 10.00 0.00 110.00 3 0.00 70.00 40.00 4 5.00 0.00 45.00 5 0.00 60.00 -15.00 6 20.00 0.00 5.00 Is it possible to do this with one query, without using a trigger or stored procedures? 回答1: Short answer, yes Longer answer, you can use a variable to tally it up as it