Thursday, March 17, 2022

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

Issue

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


Solution

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


Answered By - BitLauncher

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.