开发者

update a column by subtracting a value

开发者 https://www.devze.com 2023-02-18 16:04 出处:网络
开发者_JAVA技巧I\'m trying to come up with a MySQL query that will update points... Can I do something like this?
开发者_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

精彩评论

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