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

时间:2022-07-13 21:13:00

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.

我基本上试图将fieldA的当前值加1,即fieldA为2。

1 个解决方案

#1


27  

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.

你可以在数据库和表名周围使用反引号;但它们并非绝对必要。

#1


27  

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.

你可以在数据库和表名周围使用反引号;但它们并非绝对必要。