MySql digital functions library bitsCN.com
MySql digital functions
Abs (N) returns the absolute value of N.
Mysql> select ABS (2 );
-> 2
Mysql> select ABS (-32 );
-> 32
Sign (N) the return parameter symbol (-1, 0, or 1)
Mysql> select SIGN (-32 );
->-1
Mysql> select SIGN (0 );
-> 0
Mysql> select SIGN (1, 234 );
-> 1
Mod (N, M) modulo operation returns the remainder of N divided by M (same as % operator)
Mysql> select MOD (234, 10 );
-> 4
Mysql> select 234% 10;
-> 4
Mysql> select MOD (29,9 );
-> 2
Floor (N) returns the maximum integer not greater than N.
Mysql & gt; select FLOOR (1.23 );
-> 1
Mysql> select FLOOR (-1.23 );
->-2
Ceiling (N) returns the smallest integer not less than N.
Mysql> select CEILING (1.23 );
-> 2
Mysql> select CEILING (-1.23 );
->-1
Round (N, D) returns the rounding value of N and retains the D decimal places (the default value of D is 0)
Mysql> select ROUND (-1.23 );
->-1
Mysql> select ROUND (-1.58 );
->-2
Mysql> select ROUND (1.58 );
-> 2
Mysql> select ROUND (1.298, 1 );
-> 1.3
Mysql> select ROUND (1.298, 0 );
-> 1
Exp (N) returns the Npower of e (bottom of the natural logarithm)
Mysql> select EXP (2 );
-> 7.389056
Mysql> select EXP (-2 );
-> 0.135335
Log (N) returns the natural logarithm of N.
Mysql> select LOG (2 );
-> 0.693147
Mysql> select LOG (-2 );
-> NULL
Log10 (N) returns the base-10 logarithm of N.
Mysql> select LOG10 (2 );
-> 0.301030
Mysql> select LOG10 (100 );
-> 2.000000
Mysql> select LOG10 (-100 );
-> NULL
Pow (X, Y) or power (X, Y) returns the Y power of X.
Mysql> select POW (2, 2 );
-> 4.000000
Mysql> select POW (2,-2 );
-> 0.250000
Sqrt (N) returns the square root of non-negative N.
Mysql> select SQRT (4 );
-> 2.000000
Mysql> select SQRT (20 );
-> 4.472136
Pi () returns the circumference rate
Mysql> select PI ();
-> 3.141593
Cos (N) returns the cosine of N.
Mysql> select COS (PI ());
->-1.000000
Sin (N) returns the sine of N.
Mysql> select SIN (PI ());
-> 0.000000
Tan (N) returns the tangent of N.
Mysql> select TAN (PI () + 1 );
-> 1.557408
Acos (N) returns N arc cosine (N is the cosine value in the range from-1 to 1; otherwise, NULL is returned)
Mysql> select ACOS (1 );
-> 0.000000
Mysql> select ACOS (1.0001 );
-> NULL
Mysql> select ACOS (0 );
-> 1.570796
Asin (N) returns N arcsin.
Mysql> select ASIN (0.2 );
-> 0.201358
Mysql> select ASIN ('Foo ');
-> 0.000000
Atan (N) returns the arc tangent value of N.
Mysql> select ATAN (2 );
-> 1.107149
Mysql> select ATAN (-2 );
->-1.107149
Atan2 (X, Y) returns the arc tangent of two variables X and Y (similar to the arc tangent of Y/X, and the symbol determines the quadrant)
Mysql> select ATAN (-2, 2 );
->-0.785398
Mysql> select ATAN (PI (), 0 );
-> 1.570796
Cot (N) returns the cotangent of X.
Mysql> select COT (12 );
->-1.57267341
Mysql> select COT (0 );
-> NULL
RAND () or RAND (N) returns a random floating point value ranging from 0 to 1.0 (the number N can be used as the initial value)
Mysql> select RAND ();
-> 0.5925
Mysql> select RAND (20 );
-> 0.1811
Mysql> select RAND (20 );
-> 0.1811
Mysql> select RAND ();
-> 0.2079
Mysql> select RAND ();
-> 0.7888
Degrees (N) converts N from radians to degrees and returns
Mysql> select DEGREES (PI ());
-> 180.000000
Radians (N) converts N from angle to radians and returns
Mysql> select RADIANS (90 );
-> 1.570796
Truncate (N, D) retains the D decimal places of the number N and returns
Mysql> select TRUNCATE (1.223, 1 );
-> 1.2
Mysql> select TRUNCATE (1.999, 1 );
-> 1.9
Mysql> select TRUNCATE (1.999, 0 );
-> 1
Least (X, Y ,...) returns the minimum value (if the return value is used in the context of an integer (real number or size-sensitive string) or if all parameters are integers (real number or size-sensitive string), they are used as integers (real number or size-sensitive string) otherwise, strings with case-insensitive characters are compared)
Mysql> select LEAST (2, 0 );
-> 0
Mysql> select LEAST (34.0, 3.0, 5.0, 767.0 );
-> 3.0
Mysql> select LEAST ("B", "A", "C ");
-> ""
Greatest (X, Y,...) returns the maximum value (other values are the same as LEAST ())
Mysql> select GREATEST (2, 0 );
-> 2
Mysql> select GREATEST (34.0, 3.0, 5.0, 767.0 );
-> 767.0
Mysql> select GREATEST ("B", "A", "C ");
-> "C"
BitsCN.com