43 SQL mathematical functions
Some common math functions are given below.
ABS
absolute value
CEILING
find nearest integer, larger than the input. Ceil goes up, floor goes down.
select ceiling(0.5);
select ceiling(0.99),ceiling(0.1),ceiling(0.5);
1.0 | 1.0 | 1.0
- COS
cosine function
DEGREES
convert from radian to degrees
EXP
compute \(e^x\) power
FLOOR
find nearest integer, lesser than the input. Ceil goes up, floor goes down.
select floor(0.99),floor(0.1),floor(0.5);
0.0 | 0.0 | 0.0
LOG
logarithmic function for given base
select log(2,32);
5.0
LOG2
logarithmic function for base 2
LOG10
logarithmic function for base 10
select log10(100);
2.0
- MOD
the remainder after dividing X by Y. This is similar to the ‘%’ operator
- PI
constant PI value
POWER
compute \(x^y\) power, like \(2^3\)
select power(2,3);
RADIANS
Convert to radians from degrees
SIGN
sign of n. That is
if n<0 then -1
if n=0 then 0
if n>0 then 1
- SIN sinus function
select sin(90);
0.893996663600558
select sin(radians(90));
1.0
SQRT
square root
TAN
tangent function