开发者

update a column by subtracting a value

开发者_JAVA技巧

I'm trying to come up with a MySQL query that will update points... Can I do something like this?

UPDATE `a75ting`.`username` SET `points` = '`points` - 5'


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.


Run this query to find out the difference:

SELECT '`points` - 5' AS string, `points` - 5 AS expression
FROM a75ting.username
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜