Mysql Math functions

What are the Math Functions In MySQL?

Explanation

MySQL Math Functions :


LOG2(X) :
Returns the base-2 logarithm of X.
mysql> select log2(7215);
--> 12.816783679379
mysql> select log2(-10);
--> NULL
LOG10(X) :
Returns the base-10 logarithm of X.
mysql> select log10(5);
--> 0.69897000433602
mysql> select log10(-5);
--> NULL
MOD(N,M), N % M, N MOD M :
This function returns the remainder of N divided by M.
mysql> select mod(123, 10);
--> 3
mysql> select 111 % 8;
--> 7
mysql> select 45 mod 4;
--> 1
PI() :
Returns the value of Π(pi).
mysql> select pi();
--> 3.141593
POW(X,Y), POWER(X,Y) :
This function returns the value of XY.
mysql> select pow(3,4);
--> 81
mysql> select pow(3,-4);
--> 0.012345679012346
RADIANS(X) :
This function returns the argument X, converted from degrees to radians.
mysql> select radians(30);
--> 0.5235987755983
mysql> select radians(45);
--> 0.78539816339745
RAND(X) :
This function returns the random floating point number between 0 & 1. If a number is given within this function ,it produces repeatable sequence of values.
mysql> select rand();
--> 0.13388662052703
mysql> select rand(10);
--> 0.65705152196535
mysql> select rand(10);
--> 0.65705152196535
mysql> select rand();
--> 0.82382530888899
mysql> select rand();
--> 0.7174667135975
mysql> select rand(10);
--> 0.65705152196535
Press next to learn more mysql math functions.


Ask Questions

Ask Question