如何添加到MySQL中的每一行?

时间:2021-02-26 07:21:47

We have a column that is a simple integer. We want to add to each row the value 10. How do we do it in sql for the MySQL database?

我们有一个简单的整数列。我们想要为每一行添加值10.我们如何在sql中为MySQL数据库执行此操作?

Actually we have another column that needs to do the same thing, and it is a date. We need to add a month to the date. How to do that?

实际上我们有另一个专栏需要做同样的事情,这是一个约会。我们需要在该日期添加一个月。怎么做?

4 个解决方案

#1


14  

Integers:

整数:

UPDATE table_name SET int_column_value = int_column_value + 10;
UPDATE table_name SET int_column_value = 10 WHERE int_column_value IS NULL;

Dates:

日期:

UPDATE table_name SET date_column_value = DATEADD(date_column_value, INTERVAL 1 MONTH);

More info: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_adddate

更多信息:http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_adddate

#2


8  

 UPDATE table_name SET column_value = column_value + 10;

#3


2  

update table_name set column_name=column_name+10 where column_name is not null;

#4


2  

Should be something simple like this:

应该像这样简单:

UPDATE some_table SET int_field = int_field + 10

#1


14  

Integers:

整数:

UPDATE table_name SET int_column_value = int_column_value + 10;
UPDATE table_name SET int_column_value = 10 WHERE int_column_value IS NULL;

Dates:

日期:

UPDATE table_name SET date_column_value = DATEADD(date_column_value, INTERVAL 1 MONTH);

More info: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_adddate

更多信息:http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_adddate

#2


8  

 UPDATE table_name SET column_value = column_value + 10;

#3


2  

update table_name set column_name=column_name+10 where column_name is not null;

#4


2  

Should be something simple like this:

应该像这样简单:

UPDATE some_table SET int_field = int_field + 10