MySQL中的max(x,y)(max(x,y) in MySQL)

编程入门 行业动态 更新时间:2024-10-14 20:24:03
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

更多推荐

本文发布于:2023-08-05 20:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437671.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MySQL   max

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!