SQL数学函数
一、RAND()
说明:生成一个0-1之间的随机函数,包含0,不包含1
select rand()
二、ABS()
说明:返回绝对值
select ABS(-100)
三、CEILING()
说明:获取比当前数的最小整数
select ceiling(0.0001)
四、FLOOR()
说明:获取比当前数小的最大整数
select floor(0.999999)
五、POWER(numeric_expression , y)
说明:幂运算
numeric_expression:是精确数字或近似数字数据类型类别的表达式(bit 数据类型除外)
y:numeric_expression 的次方。y 可以是精确数字或近似数字数据类型类别的表达式(bit 数据类型除外)
select power(10,2)
六、ROUND(numeric_expression , length [ , function ] )
说明:四舍五入,只关注你指定的小数位后一位数值
- numeric_expression:是精确数字或近似数字数据类型类别(bit 数据类型除外)的表达式
- length:必须是 tinyint、smallint 或 int 类型的表达式。 如果 length 为正数,则将 numeric_expression 舍入到 length 指定的小数位数。 如果 length 为负数,则将 numeric_expression 小数点左边部分舍入到 length 指定的长度
- function:要执行的操作的类型。 function 的类型必须为 tinyint、smallint 或 int。 如果省略 function 或其值为 0(默认值),则将舍入 numeric_expression。 如果指定了 0 以外的值,则将截断 numeric_expression
select round(0.45,1)
select round(0.54,1)
select round(0.556,2,1)
七、SQRT
说明:开平方
select sqrt(9)
八、sign()
说明:正值=1,负值=-1,0=0
select sign(-100)
九、decima