How do I add to each row in MySQL?

前端 未结 4 400
失恋的感觉
失恋的感觉 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

    0 讨论(0)
  • 2021-01-17 17:33
    update table_name set column_name=column_name+10 where column_name is not null;
    
    0 讨论(0)
  • 2021-01-17 17:34
     UPDATE table_name SET column_value = column_value + 10;
    
    0 讨论(0)
  • 2021-01-17 17:36

    Should be something simple like this:

    UPDATE some_table SET int_field = int_field + 10
    
    0 讨论(0)
提交回复
热议问题