尝试使用 MySQL 将 1 添加到当前字段值,但无法弄清楚我的语法有什么问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4330805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:52:31  来源:igfitidea点击:

Trying to add 1 to current field value with MySQL, but can't figure out what's wrong with my syntax

sqlmysql

提问by Kanonskall

I'm hoping someone can spot my mistake in this MySQL query.

我希望有人能在这个 MySQL 查询中发现我的错误。

UPDATE 'databasename'.'tablename' 
   SET fieldB = fieldB + 1 
 WHERE fieldA = '2';

I'm basically trying to add 1 to the current value of fieldB where fieldA is i.e 2.

我基本上是在尝试将 fieldB 的当前值加 1,其中 fieldA 为 2。

回答by mechanical_meat

Single-quotes are for strings.

单引号用于字符串

UPDATE `databasename`.`tablename` 
SET fieldB = fieldB + 1 
WHERE fieldA = '2';

You can use backticks around the database and tablenames; they aren't strictly necessary though.

您可以在数据库和表名周围使用反引号;不过,它们并不是绝对必要的。