How do I add to each row in MySQL?

前端 未结 4 407
失恋的感觉
失恋的感觉 2021-01-17 17:16

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?

Actually we have another column th

4条回答
  •  太阳男子
    2021-01-17 17:31

    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_affffdate

提交回复
热议问题