How to limit the value of X at 100.0000 and not let it go to 105.8968?
SELECT ((15898 / (15898 + 401 + 36) * 100) + (8572 * 0.001)) AS `X`
How to limit the value of X at 100.0000 and not let it go to 105.8968?
SELECT ((15898 / (15898 + 401 + 36) * 100) + (8572 * 0.001)) AS `X`
Use LEAST function:
SELECT (LEAST(100,
(15898 / (15898 + 401 + 36) * 100) + (8572 * 0.001)
)
) AS `X`
Additional: To find maximum (reverse of Least), you can use GREATEST function
From documentation of Least():
LEAST(value1,value2,...)
With two or more arguments, returns the smallest (minimum-valued) argument. The arguments are compared using the following rules:
If any argument is NULL, the result is NULL. No comparison is needed.
If all arguments are integer-valued, they are compared as integers.
If at least one argument is double precision, they are compared as double-precision values. Otherwise, if at least one argument is a DECIMAL value, they are compared as DECIMAL values.
If the arguments comprise a mix of numbers and strings, they are compared as numbers.
If any argument is a nonbinary (character) string, the arguments are compared as nonbinary strings.
In all other cases, the arguments are compared as binary strings.
The return type of LEAST() is the aggregated type of the comparison argument types.
Use LEAST()
:
SELECT LEAST((15898 / (15898 + 401 + 36) * 100) + (8572 * 0.001), 100.0000) AS `X`