0% found this document useful (0 votes)
362 views

Calculating Opening Balance of A Month Using Mysql - Stack Overflow

Balance Calculations

Uploaded by

Taha G
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
362 views

Calculating Opening Balance of A Month Using Mysql - Stack Overflow

Balance Calculations

Uploaded by

Taha G
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Search… Log In Sign Up

Home Calculating opening balance of a month using Mysql Ask Question

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?

mysql 2346 Should I use the datetime or timestamp


data type in MySQL?

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

1006 How to reset AUTO_INCREMENT in


Provide more details – Abhishek Ginani Dec 18 '15 at 4:50
MySQL?
I have DebitAmount, CreditAmount and Date in my table. I want to calculate opening balance up to a selected
month. – Anju Mathew Dec 18 '15 at 4:58 0 maintaning opening and closing balance for
each row in a ledger table
provide table structure and expected output with sample data. – Avi Dec 18 '15 at 5:00
1367 How to import an SQL file using the
TransactionId DebitAmount CreditAmount TransactionDate ------------- ----------- ------------ ---------------- 1 40000 command line in MySQL?
500000 2015-12-07 2 60000 700000 2015-12-08 3 90000 800000 2015-12-11 4 5000 3000 2015-12-11 5
70000 90000 2015-12-11 Input: Month : Jan Expected Output OpeningBalance -------------- Debit :
SomeAmount Credit : SomeAmount – Anju Mathew Dec 18 '15 at 5:10
Hot Network Questions
How do I make a space battle both realistic, with
add a comment
physics in play such as no sound and weird
motion, but also very epic and intense still?
1 Answer active oldest votes What does Kanye (Ye) West actually mean by
"Abolish the 13th Amendment"?

How can I ensure my Evil Tower is always stormy?


You can try something like this, if I am understanding correctly: What sets have been named in a punny way?

Customised shoes at Airport security check


0 select
concat('Debit: ', sum(debitamount)) as 'Opening Balance'
Logged out of Facebook on all devices on a
from test
sudden. Should I be worried about being hacked?
where
month(transactiondate) = month( date_sub('2016-01-01', interval day('2016-01-01')+1 day) ) Could Black holes forge heavier elements that
and year(transactiondate) = year( date_sub('2016-01-01', interval day('2016-01-01')+1 day) have yet to be discovered?

Does America not lead the world in mass


union all
shootings?
select What happens if only rudder is applied in a turn
concat('Credit: ', sum(creditamount)) without ailerons? Do the two have to be applied
from test together all the time?
where
Offensive language/behavior from co-worker in
month(transactiondate) = month( date_sub('2016-01-01', interval day('2016-01-01')+1 day) )
online game
and year(transactiondate) = year( date_sub('2016-01-01', interval day('2016-01-01')+1 day)
What issue does the EU take with the UK's
Chequers proposal?
If your data looked like this: Query replace with different replacements

+---------------+-------------+--------------+-----------------+ What do Democrats have to gain, politically, by


| transactionid | debitamount | creditamount | transactiondate | preventing Brett Kavanaugh's appointment to the
+---------------+-------------+--------------+-----------------+ Supreme Court?
| 1 | 100 | 200 | 2015-12-05 | Can one eat a balanced diet if one only cooks
| 2 | 200 | 400 | 2015-12-05 | once a week?
+---------------+-------------+--------------+-----------------+
Black screen on login, gnome-shell eating 100% of
CPU
Result:
Why is this definition of convergence incorrect?
+-----------------+ Why do reflections on a rough surface stretch
| Opening Balance | towards you instead of spreading out in all
+-----------------+ directions?
| Debit: 300 |
| Credit: 600 | Is there any technical reason why, in
+-----------------+ programming, the default date format is
YYYYMMDD and not something else?

EDIT: why is \chapter blocking page foot

Paradox about the volume of a cylinder


Based on the opening balance calculation here's the query
When should you create your own exception type?
select
concat('Opening balance: ', sum(creditamount-debitamount)) as result Crossing the road in London - Did I have 'right of
from test way'?
where Why does the LIGO observation disprove higher
month(transactiondate) = month( date_sub('2016-01-01', interval day('2016-01-01')+1 day) ) dimensions?
and year(transactiondate) = year( date_sub('2016-01-01', interval day('2016-01-01')+1 day)
ZFS: re-compress existing files after change in
union all compression algorithm

select question feed


concat('Debit: ', sum(debitamount))
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)

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

Update added based on your comment – zedfoxus Dec 18 '15 at 5:58

Thanks. I think this will work. – Anju Mathew Dec 18 '15 at 6:05

add a comment

Your Answer

Sign up or log in Post as a guest

Sign up using Google Name

Sign up using Facebook Email

required, but never shown


Sign up using Email and Password

Post 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

You might also like