MySQL中的max(x,y)(max(x,y) in MySQL)
对于下表(所有列都是整数)
[id, value, best_value]对于给定的id和值,我想更新它的行,将best_value列设置为max(newvalue,best_value)。 我进入了文档,但我没有看到这样做的功能。
谢谢
For the following table (all columns are integers)
[id, value, best_value]For a given id and value I want update it's row setting the best_value column to max(newvalue,best_value). I seached into the documentation but I dont see a function for doing so.
Thanks
最满意答案
你想要GREATEST(x,y) 。 例如,如果新值为530:
UPDATE my_table SET best_value = GREATEST(530,best_value) WHERE id=123
You want GREATEST(x,y). Example, if the new value is 530:
UPDATE my_table SET best_value = GREATEST(530,best_value) WHERE id=123
更多推荐
发布评论