如何在MySQL中添加到每一行? [英] How do I add to each row in MySQL?

查看:173
本文介绍了如何在MySQL中添加到每一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一列,它是一个简单的整数.我们想在每行中添加值10.如何在mysql中的sql中使用它?

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 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?

推荐答案

整数:

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;

日期:

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

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

这篇关于如何在MySQL中添加到每一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆