All mathematical functions returns NULL in the case of a error.
-
mysql> select - 2; -> -2
ABS()
mysql> select abs(2); -> 2 mysql> select abs(-32); -> 32
SIGN()
mysql> select sign(-32); -> -1 mysql> select sign(0); -> 0 mysql> select sign(234); -> 1
MOD()
%
mysql> select mod(234, 10); -> 4 mysql> select 253 % 7; -> 1 mysql> select mod(29,9); -> 2
FLOOR()
mysql> select floor(1.23); -> 1 mysql> select floor(-1.23); -> -2
CEILING()
mysql> select ceiling(1.23); -> 2 mysql> select ceiling(-1.23); -> -1
ROUND(N)
N to an integer.
mysql> select round(-1.23); -> -1 mysql> select round(-1.58); -> -2 mysql> select round(1.58); -> 2
ROUND(Number,Decimals)
Number to a number with Decimals decimals.
mysql> select ROUND(1.298, 1); -> 1.3
EXP(N)
e (the base of natural logarithms) raised to
the power of N.
mysql> select exp(2); -> 7.389056 mysql> select exp(-2); -> 0.135335
LOG(X)
X.
mysql> select log(2); -> 0.693147 mysql> select log(-2); -> NULL
LOG10(X)
X.
mysql> select log10(2); -> 0.301030 mysql> select log10(100); -> 2.000000 mysql> select log10(-100); -> NULL
POW(X,Y)
POWER(X,Y)
X raised to the power of Y.
mysql> select pow(2,2); -> 4.000000 mysql> select pow(2,-2); -> 0.250000
sqrt(X)
X.
mysql> select sqrt(4); -> 2.000000 mysql> select sqrt(20); -> 4.472136
PI()
mysql> select PI(); -> 3.141593
COS(X)
X, where X is given in radians.
mysql> select cos(PI()); -> -1.000000
SIN(X)
X, where X is given in radians.
mysql> select sin(PI()); -> 0.000000
TAN(X)
X, where X is given in radians.
mysql> select tan(PI()+1); -> 1.557408
ACOS(X)
X; that is the value whose cosine is
X. If X is not in the range -1 to 1 NULL is
returned.
mysql> select ACOS(1); -> 0.000000 mysql> select ACOS(1.0001); -> NULL mysql> select ACOS(0); -> 1.570796
ASIN(X)
X; that is the value whose sine is
X. If X is not in the range -1 to 1 NULL is
returned.
mysql> select ASIN(0.2); -> 0.201358
mysql> select ASIN('foo'); -> 0.000000
ATAN(X)
X; that is the value whose tangent is
X.
mysql> select ATAN(2); -> 1.107149 mysql> select ATAN(-2); -> -1.107149
ATAN2(X,Y)
X and Y. It is
similar to calculating the arc tangent of Y / X, except that the
signs of both arguments are used to determine the quadrant of the
result.
mysql> select ATAN(-2,2); -> -0.785398 mysql> select ATAN(PI(),0); -> 1.570796
COT(N)
N.
mysql> select COT(12); -> -1.57267341 mysql> select COT(0); -> NULL
RAND([X])
0 <= x <= 1.0, using the integer
expression X as the optional seed 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.7888One can't do a ORDER BY on a column with RAND() values because ORDER BY would evaluate the column multiple times.
MIN(X,Y...)
GROUP BY functions. The arguments are compared as numbers. If no
records are found NULL is returned.
mysql> SELECT MIN(2,0); -> 0 mysql> SELECT MIN(34,3,5,767); -> 3 mysql> SELECT MIN(a) from table where 1=0; -> NULL
MAX(X,Y...)
GROUP BY functions. The arguments are compared as numbers. If no
records are found NULL is returned.
mysql> SELECT MAX(34,3,5,767); -> 767 mysql> SELECT MAX(2,0,4,5,34); -> 34 mysql> SELECT MAX(a) from table where 1=0; -> NULL
DEGREES(N)
N converted from radians to degrees.
mysql> select DEGREES(PI()); -> 180.000000
RADIANS(N)
N converted from degrees to radians.
mysql> select RADIANS(90); -> 1.570796
TRUNCATE(Number, Decimals)
Number to Decimals decimals.
mysql> select TRUNCATE(1.223,1); -> 1.2 mysql> select TRUNCATE(1.999,1); -> 1.9 mysql> select TRUNCATE(1.999,0); -> 1
Go to the first, previous, next, last section, table of contents.