📜  mysql update set sum - SQL (1)

📅  最后修改于: 2023-12-03 15:33:02.133000             🧑  作者: Mango

MySQL UPDATE SET SUM - SQL

MySQL UPDATE SET SUM is a SQL command used to update the values of a column in a MySQL database table by adding a specified value to the existing values in the column. This command is particularly useful in situations where you want to increase the value of a column by a certain amount.

Syntax

The syntax for using MySQL UPDATE SET SUM is as follows:

UPDATE table_name
SET column_name = column_name + value
WHERE condition;

Here, table_name is the name of the table in which the column is located, column_name is the name of the column that you want to update, value is the amount by which you want to increase the value of the column, and condition specifies the rows to be updated.

Example

To better understand how MySQL UPDATE SET SUM works, let's take a look at an example. Suppose we have a table named sales with columns id, name, and sales_amount. We want to increase the value of the sales_amount column for a specific row by 100.

The SQL query to accomplish this using MySQL UPDATE SET SUM would be:

UPDATE sales
SET sales_amount = sales_amount + 100
WHERE id = 1;

This query would add 100 to the sales_amount column for the row with an id of 1.

Conclusion

In conclusion, MySQL UPDATE SET SUM is a powerful SQL command that allows you to update the values of a column in a MySQL database table by adding a specified value to the existing values in the column. By understanding the syntax and usage of this command, you can easily update your database tables to reflect the latest information.