轉(zhuǎn)自公眾號‘java一日一條’
2.數(shù)學(xué)函數(shù)
abs(n)
返回n的絕對值
mysql> select abs(2);
-> 2
mysql> select abs(-32);
-> 32
sign(n)
返回參數(shù)的符號(為-1潦蝇、0或1)
mysql> select sign(-32);
-> -1
mysql> select sign(0);
-> 0
mysql> select sign(234);
-> 1
mod(n,m)
取模運算,返回n被m除的余數(shù)(同%操作符)
mysql> select mod(234, 10);
-> 4
mysql> select 234 % 10;
-> 4
mysql> select mod(29,9);
-> 2
floor(n)
返回不大于n的最大整數(shù)值
mysql> select floor(1.23);
-> 1
mysql> select floor(-1.23);
-> -2
ceiling(n)
返回不小于n的最小整數(shù)值
mysql> select ceiling(1.23);
-> 2
mysql> select ceiling(-1.23);
-> -1
round(n,d)
返回n的四舍五入值,保留d位小數(shù)(d的默認(rèn)值為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)
返回值e的n次方(自然對數(shù)的底)
mysql> select exp(2);
-> 7.389056
mysql> select exp(-2);
-> 0.135335
log(n)
返回n的自然對數(shù)
mysql> select log(2);
-> 0.693147
mysql> select log(-2);
-> null
log10(n)
返回n以10為底的對數(shù)
mysql> select log10(2);
-> 0.301030
mysql> select log10(100);
-> 2.000000
mysql> select log10(-100);
-> null
pow(x,y)
power(x,y)
返回值x的y次冪
mysql> select pow(2,2);
-> 4.000000
mysql> select pow(2,-2);
-> 0.250000
sqrt(n)
返回非負(fù)數(shù)n的平方根
mysql> select sqrt(4);
-> 2.000000
mysql> select sqrt(20);
-> 4.472136
pi()
返回圓周率
mysql> select pi();
-> 3.141593
cos(n)
返回n的余弦值
mysql> select cos(pi());
-> -1.000000
sin(n)
返回n的正弦值
mysql> select sin(pi());
-> 0.000000
tan(n)
返回n的正切值
mysql> select tan(pi()+1);
-> 1.557408
acos(n)
返回n反余弦(n是余弦值,在-1到1的范圍,否則返回null)
mysql> select acos(1);
-> 0.000000
mysql> select acos(1.0001);
-> null
mysql> select acos(0);
-> 1.570796
asin(n)
返回n反正弦值
mysql> select asin(0.2);
-> 0.201358
mysql> select asin('foo');
-> 0.000000
atan(n)
返回n的反正切值
mysql> select atan(2);
-> 1.107149
mysql> select atan(-2);
-> -1.107149
atan2(x,y)
返回2個變量x和y的反正切(類似y/x的反正切,符號決定象限)
mysql> select atan(-2,2);
-> -0.785398
mysql> select atan(pi(),0);
-> 1.570796
cot(n)
返回x的余切
mysql> select cot(12);
-> -1.57267341
mysql> select cot(0);
-> null
rand()
rand(n)
返回在范圍0到1.0內(nèi)的隨機(jī)浮點值(可以使用數(shù)字n作為初始值)
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)
把n從弧度變換為角度并返回
mysql> select degrees(pi());
-> 180.000000
radians(n)
把n從角度變換為弧度并返回
mysql> select radians(90);
-> 1.570796
truncate(n,d)
保留數(shù)字n的d位小數(shù)并返回
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,...)
返回最小值(如果返回值被用在整數(shù)(實數(shù)或大小敏感字串)上下文或所有參數(shù)都是整數(shù)(實數(shù)或大小敏感字串)則他們作為整數(shù)(實數(shù)或大小敏感字串)比較,否則按忽略大小寫的字符串被比較)
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");
-> "a"
greatest(x,y,...)
返回最大值(其余同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"