Click here to Skip to main content
15,899,679 members

Comments by Member 10361041 (Top 5 by date)

Member 10361041 5-May-15 22:31pm View    
ok, thanks! This is my first post in ever to ask a question. Anyway Thank you sooo much!

I tried to update my table. But i didn't look about select. This is what i searched. Thank you again.

http://www.mysqltutorial.org/mysql-tips/mysql-compare-calculate-difference-successive-rows/

And also i improve it for a my result.

select a.addedDateTime, a.credit, a.debit, a.balance from creditors a limit 1
union all
select a.addedDateTime, a.credit, a.debit, b.balance + a.debit - a.credit as balance
from creditors a inner join creditors b
on a.id - 1 = b.id

Thank you!
Member 10361041 5-May-15 22:16pm View    
Oh, sorry! I forgot to tell you I add another column which includes auto increment primary key. That's what i used as "id" in my procedure query.

That table also generating via procedure. Then i can edit it also!
Thank you!
Member 10361041 5-May-15 12:50pm View    
It's optional! it isn't depend on number of accounts. But if you can do it for one account we can improve it for all.
I found a solution using stored procedure. But if can give a single query for it, it's very useful!
Thank you!
Member 10361041 5-May-15 11:16am View    
Yes, u get it correctly! But your query is not works fine!
If your can please try it with a table and some rows.(3 or more rows)
columns should be "credit", "debit" and "balance".
eg :-
CREDIT, DEBIT, BALANCE
100 ,0 , 0
50 ,0 , 0
0 ,200 , 0
120 ,0 , 0
100 ,0 , 0
0 ,100 , 0
0 ,100 , 0

After process table row values should be
CREDIT, DEBIT, BALANCE
100 ,0 , -100
50 ,0 , -150
0 ,200 , 50
120 ,0 , -70
100 ,0 , -170
0 ,100 , -70
0 ,100 , 30
Member 10361041 5-May-15 8:07am View    
I'm working with accounting pack in java and i wanna generate reports just using queries without java codes.
I wrote a stored procedure to generate a result table using many data tables.
it has 5 columns. name, date, credit, debit and balance.
I wrote a query to fill data from other tables. But i couldn't calculate balance from credit and debit.

Balance = last balance + debit - credit;

But finally i could to write stored procedure for it.

Thank you!

Have you another solution?