mysql 常用math函数

ABS(x)   返回x的绝对值

BIN(x)   返回x的二进制(OCT返回八进制,HEX返回十六进制)
CEILING(x)   返回大于x的最小整数值
EXP(x)   返回值e(自然对数的底)的x次方
FLOOR(x)   返回小于x的最大整数值
GREATEST(x1,x2,...,xn)返回集合中最大的值
LEAST(x1,x2,...,xn)      返回集合中最小的值
LN(x)                    返回x的自然对数
LOG(x,y)返回x的以y为底的对数
MOD(x,y)                 返回x/y的模(余数)
PI()返回pi的值(圆周率)
RAND()返回0到1内的随机值,可以通过提供一个参数(种子)使RAND()随机数生成器生成一个指定的值。
ROUND(x,y)返回参数x的四舍五入的有y位小数的值
SIGN(x) 返回代表数字x的符号的值
SQRT(x) 返回一个数的平方根
TRUNCATE(x,y)            返回数字x截短为y位小数的结果
 
更多内容:http://dev.mysql.com/doc/refman/5.5/en/mathematical-functions.html
 
round 四舍五入的一个案例:
Rounds the argument X to D decimal places. The rounding algorithm depends on the data type of XD defaults to 0 if not specified. Dcan be negative to cause D digits left of the decimal point of the value X to become zero. 
          

+-----------------+----------------+----------------+

| round(36.45,-1) | round(36.45,1) | round(36.45,0) |

+-----------------+----------------+----------------+

|              40 |           36.5 |             36 |

+-----------------+----------------+————————+

原文地址:https://www.cnblogs.com/07byte/p/5823657.html