How to Calculate a Running Balance With MySQL

MySQL lets you perform calculations while you retrieve data, allowing you to add and subtract numbers to display a total running balance. MySQL uses the SQL language to query the database, and the language uses the "Sum" function to add totals in the database. Use this function to add up all expenses and all income to return the balance calculation.

Instructions

    • 1

      Click "Start" and select "All Programs." Click "MySQL," then click "Query Browser" to open the MySQL programming software.

    • 2

      Log in to your MySQL database using your username and password. The query editor displays.

    • 3

      Type the following code to display the balance for the two totals:

      select sum(income)-sum(expenses) from income_table

      This code subtracts the total amount of expenses from the total amount of income. If income is greater than expenses, the result shown is positive; a negative number displays if there are more expenses than income. Replace "income_table" with the table that contains the income and expenses.

Related Searches:

References

Comments

Related Ads

Featured