目录
[1. 随机数生成 rand ( )](#1. 随机数生成 rand ( ))
[2. 四舍五入 round()](#2. 四舍五入 round())
[3. 舍去 truncate ( )](#3. 舍去 truncate ( ))
[4. 向上/下取整](#4. 向上/下取整)
[5. 空处理 ifnull( x , y )](#5. 空处理 ifnull( x , y ))
1. 随机数生成 rand ( )
rand ( ) 生成 0 到 1 的随机数;
rand ( x ) 生成 0 到 1 的随机数,且随机数不变;
比如:select rand ( ) ;

比如:select rand ( 3 ) ;
2. 四舍五入 round()
保留整数:round ( x );
保留小数点后 y 位:round(x,y);
比如 select round ( 3.333 ) ;
比如 select round ( 3.333 ,1) ;

3. 舍去 truncate ( )
保留 y 位小数,其余直接舍去: truncate ( x,y );

4. 向上/下取整
向上取整:ceil();
向下取整:floor();
向上取整:select ceil ( 3.333 ) ;

向下取整:select floor ( 3.333 ) ;

5. 空处理 ifnull( x , y )
但凡有 NULL 参与的数学运算,结果都为 NULL ,这在实际应用中是不合理的,需要规避的;

ifnull可以解决这个问题了。
ifnull (x,y) 意为如果 x 为null ,将 y 取代 x 进行计算;
比如:

这在计算员工的年薪等实际应用中值得注意;