Calculating Opening Balance of A Month Using Mysql - Stack Overflow
Calculating Opening Balance of A Month Using Mysql - Stack Overflow
PUBLIC
Could someone explain the simplest method of calculating opening balance of a month using Mysql. asked 2 years, 9 months ago
Stack Overflow
For calculating opening balance I have month as input and debit amount and credit as table fields. I
viewed 647 times
Tags -1 want to calculate opening balance up to a particular month.
active 2 years, 9 months ago
Users TransactionId DebitAmount CreditAmount TransactionDate
------------- ---------- ------------ ----------------
Jobs 1 40000 500000 2015-12-07
2 60000 700000 2015-12-08
Related
3 90000 800000 2015-12-11
4 5000 3000 2015-12-11 978 Can I concatenate multiple MySQL rows
Teams
5 70000 90000 2015-12-11 into one field?
Q&A for work
Input: Month : Jan 1018 Which MySQL data type to use for storing
Learn More boolean values
Expected Output
954 How to output MySQL query results in CSV
OpeningBalance
format?
--------------
Debit : SomeAmount
984 How do I connect to a MySQL Database in
Credit : SomeAmount
Python?
share improve this question 542 MySQL Query GROUP BY day / month /
edited Dec 18 '15 at 5:26 asked Dec 18 '15 at 4:44
year
zedfoxus Anju Mathew
17.5k 4 27 41 8 6 1230 How to get a list of MySQL user accounts
union all
select
concat('Credit: ', sum(creditamount))
from test
where
month(transactiondate) = month( date_sub('2016-01-01', interval day('2016-01-01')+1 day) )
and year(transactiondate) = year( date_sub('2016-01-01', interval day('2016-01-01')+1 day)
Result:
+----------------------+
| result |
+----------------------+
| Opening balance: 300 |
| Debit: 300 |
| Credit: 600 |
+----------------------+
share improve this answer edited Dec 18 '15 at 5:58 answered Dec 18 '15 at 5:29
zedfoxus
17.5k 4 27 41
Thank you for your response. But I think the equation for calculating opening balance is
capital=sum(creditedamount)-sum(debitedamount) and I if capital is +ve then opening balance is credit
otherwise debit. – Anju Mathew Dec 18 '15 at 5:53
Thanks. I think this will work. – Anju Mathew Dec 18 '15 at 6:05
add a comment
Your Answer
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie
policy, and that your continued use of the website is subject to these policies.
Not the answer you're looking for? Browse other questions tagged mysql or ask your own question.
STACK OVERFLOW PRODUCTS COMPANY STACK EXCHANGE Blog Facebook Twitter LinkedIn
NETWORK
Questions Teams About
Technology
Jobs Talent Press
Life / Arts
Developer Jobs Directory Engagement Work Here
Culture / Recreation
Salary Calculator Enterprise Legal
Science
Help Privacy Policy
Other
Mobile Contact Us site design / logo © 2018 Stack Exchange Inc; user contributions
licensed under cc by-sa 3.0 with attribution required.
Disable Responsiveness rev 2018.9.28.31767