Skip to content
Advertisement

Using MySQL to calculate difference of 2 columns to equal a 3rd column

Ok so I’m using SQL in phpmyadmin trying to calculate the difference from 2 columns and add that value to a 3rd column. I’ve imported my data by CSV into the database. I’m trying to “autosum” like excel and Access in SQL database.

My columns are “Tax Collected” – “Tax Paid” = “Tax Gain”

Imported CSV

Advertisement

Answer

That we could proper answer, you should best provide e. g. the table create statement, I assume here that you already defined/added a 3rd column of proper data type and default NULL.

This can IMHO be done with standard SQL command like e. g.

   UPDATE 
     YourTableName
   SET 
     TaxGain = TaxCollected - TaxPaid
   WHERE 
     TaxGain IS NULL
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement