更新时间:2022-06-03 03:21:41
一个简单的增量就可以解决问题.
A simple increment should do the trick.
UPDATE mytable
SET logins = logins + 1
WHERE id = 12
如果您想更新先前存在的行,或者如果不存在则将其插入,则可以使用 INSERT...ON DUPLICATE KEY UPDATE
选项(如 Rob Van Dam 在他的答案中进行了演示.
If you would like to update a previously existing row, or insert it if it doesn't already exist, you can use the REPLACE
syntax or the INSERT...ON DUPLICATE KEY UPDATE
option (As Rob Van Dam demonstrated in his answer).
或者您正在寻找类似 INSERT...MAX(logins)+1
之类的东西?本质上,您将运行类似于以下内容的查询-根据您的特定需求,可能会更复杂一些:
Or perhaps you're looking for something like INSERT...MAX(logins)+1
? Essentially you'd run a query much like the following - perhaps a bit more complex depending on your specific needs:
INSERT into mytable (logins)
SELECT max(logins) + 1
FROM mytable