mysql 增加数字_如何在MySQL中将数字添加到当前值(同时多次)?

您可以为此使用UPDATE命令。

语法如下update yourTableName set yourColumnName =yourColumnName +yourIntegerValue where ;

为了理解上述语法,让我们创建一个表。创建表的查询如下mysql> create table addANumberToCurrentValueDemo

-> (

-> Game_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,

-> Game_Score int

-> );

现在,您可以使用insert命令在表中插入一些记录。查询如下-mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(1090);

mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(204);

mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(510);

mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(7890);

mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(8999);

mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(1093859);

mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(157596);

mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(4857567);

现在,您可以使用select语句显示表中的所有记录。

查询如下-mysql> select *from addANumberToCurrentValueDemo;

以下是输出+---------+------------+

| Game_Id | Game_Score |

+---------+------------+

|       1 | 1090       |

|       2 | 204        |

|       3 | 510        |

|       4 | 7890       |

|       5 | 9290       |

|       6 | 1093859    |

|       7 | 157596     |

|       8 | 4857567    |

+---------+------------+

8 rows in set (0.05 sec)

这是在MySQL中向当前值添加数字的查询mysql> update addANumberToCurrentValueDemo set Game_Score=Game_Score+11 where Game_Id=5;

Rows matched: 1 Changed: 1 Warnings: 0

现在,再次检查表记录,以验证Game_Score列已从8999更新为9010。

查询如下-mysql> select *from addANumberToCurrentValueDemo;

以下是输出+---------+------------+

| Game_Id | Game_Score |

+---------+------------+

|       1 | 1090       |

|       2 | 204        |

|       3 | 510        |

|       4 | 7890       |

|       5 | 9301       |

|       6 | 1093859    |

|       7 | 157596     |

|       8 | 4857567    |

+---------+------------+

8 rows in set (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值