1

How can I update sum of data from different columns from 1 table to a different column in the same table?

Below is the example:

Name     Jan_Sales Feb_Sales March_Sales  Total_Sales
Cathey   345         450      530            ?
Susan    456         280      430            ?
Jason    346         590      567            ?
Chris    478         344      345            ?

I want to update column Total_Sales by summing Jan, Feb, Mar sales.. For e.g 1325(345+450+530) in total_sales for Cathey.

2 Answers 2

1

Try this:

update yourtable
set total_sales = jan_sales + feb_sales + march_sales
Sign up to request clarification or add additional context in comments.

Comments

1

This may work :

UPDATE
    table_name 
SET 
    Total_Sales = Jan_Sales + Feb_Sales + March_Sales
WHERE 1 = 1;

where 1=1 is to prevent mysql to warn that you are performing an UPDATE without WHERE clause

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.