mysql 函数--数学函数

          mysql 函数


————数学函数,以下代码全都经过验证,可放心使用:


-- 绝对值函数ABS(x)和返回圆周率的函数PI()
-- 1.1 求2,-3.3 ,-33的绝对值:
select abs(2),abs(-3.3),abs(-33);
-- 1.2 返回圆周率:
select pi();

-- 平方根函数SQRT(x)和求余函数MOD(x,y)
-- 1.3 求9,40,-49的二次平方根
select sqrt(9), sqrt(40), sqrt(-49);
-- 1.4 对mod(31,8),mod(234,10),mod(45.5,6)进行求余运算
select mod(31,8),mod(234,10),mod(45.4,6);

-- 获取整数的函数 ceil(x),ceiling(x)和floor(x)
-- 1.5 使用celing函数返回最小整数
select ceil(-3.35),ceiling(3.37);
-- 1.6 使用floor函数返回最大整数
select floor(-3.37),floor(3.37);

-- 获取随机数的函数rand(),和rand(x)
-- 1.7 使用rand()产生随机数
select rand(),rand(),rand();
-- 1.8 使用rand(x)产生随机数,相同的x产生相同的值,不同的x产生的随机数不相同。
select rand(1),rand(1),rand(1),rand(4),rand(44);

-- 四舍五入函数round(x) round(x,y) 和truncate(x,y)
-- 1.9 使用round(x),round函数返回最接近于参数x的整数
select round(4.3),round(4.5),round(4.8),round(-3.4),round(-3.7);
-- 1.10 使用round(x,y)函数对操作数进行四舍五入操作,结果保留小数点后面指定y位
select round(34.432,1),round(-2.632,2),round(234.34,-2);
-- 1.11 使用truncate(x,y)函数对操作数四舍五入操作,结果保留小数点后面指定的y位
select truncate(1.32,1),truncate(1.99,1),truncate(1.99,0),truncate(19.99,-1);

-- 符号函数sign(x)
-- 1.12 使用sign(x)
select sign(-31),sign(0),sign(13);

-- 幂运算函数pow(x,y) power(x,y) 和exp(x)
-- 1.13 pow 和 power 函数
select pow(2,3),power(2,4),pow(2,-2),power(2,-2);
-- 1.14 exp函数计算e的乘方
select exp(3),exp(-3),exp(0);

-- 对数运算函数log(x)和log10(x)
-- 1.15使用log(x)计算自然对数:
select log(3),log(-3);
-- 1.16 使用log10计算以10为基数的对数
select log10(100),log10(-100),log10(2);

-- 角度与弧度相互转换的函数radians(x)和degrees(x)
-- 1.17 使用radians 将角度转换为弧度
select radians(30),radians(90),radians(180);
-- 1.18 使用degrees将弧度转换为角度
select degrees(pi()),degrees(pi()/2);

-- 正弦函数sin(x)和反正弦函数asin(x)
-- 1.19 使用sin函数计算正弦值
select sin(1);
-- 1.20 使用反正弦函数计算
select asin(3),asin(0.7);

-- 余弦函数cos(x)和反余弦函数acos(x)
-- 1.21 使用cos
select cos(0),cos(pi()),cos(1);
-- acos函数
select acos(1),acos(-1);

-- 正切函数、反切函数,和余切函数
-- 1.22 tan(x)
select tan(10);
-- 1.23 atan(x);
select atan(1);
-- 1.24 cot()
select cot(3);

























猜你喜欢

转载自blog.csdn.net/weixin_42321963/article/details/80991800