I Have two columns Debit and Credit and want query to calculate balance from debit and credit for individual customer as shown below in the image:
-
What version of MySQL?– J.D.Jan 23, 2022 at 16:06
-
Man, the price of these pencils!– Gerard H. PilleJan 23, 2022 at 16:11
-
mysql version is mysqlnd 8.0.6– Sikander ShahzadJan 23, 2022 at 16:28
-
Mr. Gerard H.Pille , dummy data..... what i want is ledger_balance column as ouput from columns ledger_debit and ledger_credit order by ledger_id– Sikander ShahzadJan 23, 2022 at 16:36
Add a comment
|
1 Answer
Got my solution: select ledger_date ,ledger_desc ,ledger_debit, ledger_credit, sum(ledger_debit) over (order by ledger_id) - sum(ledger_credit) over (order by ledger_id) as Balance from tblledger
-
As long as there is but one customer. The problem doesn't require window functions (over (...)). Jan 23, 2022 at 18:44
-
Hi, and welcome to dba.se! Please format your answer using the tools above the edit box.– VéraceJan 24, 2022 at 0:22