I have been searching, but all I find are answers on how to Find, not SET the maximum return value of a function.
我一直在寻找,但我找到的只是如何查找的答案,而不是设置函数的最大返回值。
What I am looking for is simple.. If I want to update the entries in a column in proportion to themselves.. say.. SET TheColumValue
=(TheColumnValue
+(TheColumnValue*0.5));
我正在寻找的是简单的..如果我想按照自己的比例更新列中的条目..说.. SET TheColumValue =(TheColumnValue +(TheColumnValue * 0.5));
Is there no MYSQL function to limit the resulting value?
是否没有MYSQL函数来限制结果值?
SET TheColumValue
=FUNCTIONNAME(TheColumnValue
+(TheColumnValue*0.5), MAXIMUMVALUE);
SET TheColumValue = FUNCTIONNAME(TheColumnValue +(TheColumnValue * 0.5),MAXIMUMVALUE);
I have written my own function to handle the need for now, but it seems to me such a simple, and obvious need that it would be part of the language. Am I just not finding it in the Ref. manual or does such a function actually not exist in MYSQL?
我已经编写了自己的函数来处理现在的需求,但在我看来,这是一个简单而明显的需求,它将成为语言的一部分。我只是在参考文献中找不到它。手动还是MYSQL中实际上不存在这样的功能?
1 个解决方案
#1
Of course there is. It is called LEAST()
:
当然有。它被称为LEAST():
SET TheColumValue = LEAST(TheColumnValue+(TheColumnValue*0.5), MAXIMUMVALUE)
More succinctly written as:
更简洁地写成:
SET TheColumValue = LEAST(TheColumnValue * 1.5, MAXIMUMVALUE)
#1
Of course there is. It is called LEAST()
:
当然有。它被称为LEAST():
SET TheColumValue = LEAST(TheColumnValue+(TheColumnValue*0.5), MAXIMUMVALUE)
More succinctly written as:
更简洁地写成:
SET TheColumValue = LEAST(TheColumnValue * 1.5, MAXIMUMVALUE)