MySQL 通过减去一个值来更新列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5383108/
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
update a column by subtracting a value
提问by Shawn
I'm trying to come up with a MySQL query that will update points
... Can I do something like this?
我正在尝试提出一个将更新的 MySQL 查询points
......我可以做这样的事情吗?
UPDATE `a75ting`.`username` SET `points` = '`points` - 5'
回答by Marc B
UPDATE a75ting.username
SET points = points - 5
by putting the single quotes around the "points -5", you converted that expression into a plaintext string. Leaving it without the quotes lets MySQL see you're referring to a field (points) and subtracting 5 from its current value.
通过将单引号放在“points -5”周围,您可以将该表达式转换为纯文本字符串。不带引号让 MySQL 看到您指的是一个字段(点)并从其当前值中减去 5。
回答by álvaro González
Run this query to find out the difference:
运行此查询以找出差异:
SELECT '`points` - 5' AS string, `points` - 5 AS expression
FROM a75ting.username