I have a table below
first second
------- ----------
100 0
200 0
0 400
I want to get the result below
first second result
------- ---------- ----------
100 0 100
200 0 300
0 400 -100
As you can see, this result parameter is the sum of the previous one (first sum). How can I write such a request?
DecisionMYSQL is very simple, but simple solutions are looking for Microsoft Sql Server.
set @result =0;
select first, second, @result := @result + first - second as result
from tablo;
results
first second result
100 0 100
200 0 300
0 400 -100
source
share