update a column by subtracting a value

后端 未结 2 1544
不思量自难忘°
不思量自难忘° 2020-12-14 16:50

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` = \'         


        
相关标签:
2条回答
  • 2020-12-14 17:19
    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.

    0 讨论(0)
  • 2020-12-14 17:30

    Run this query to find out the difference:

    SELECT '`points` - 5' AS string, `points` - 5 AS expression
    FROM a75ting.username
    
    0 讨论(0)
提交回复
热议问题