欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MSSQL SERVER 2005 数学函数整理

程序员文章站 2023-12-16 18:29:28
mssql server 2005 数学函数 1.求绝对值 abs() select fweight-50,abs(fweight-50),abs(-5.38) from...
mssql server 2005 数学函数
1.求绝对值
abs()
select fweight-50,abs(fweight-50),abs(-5.38) from t_person
2.求幂
power(x,y) 用来计算x的y次幂
select fweight,power(fweight,-0.5),power(fweight,2),
power(fweight,3),power(fweight,4) from t_person
select power(2,2)
3.求平方根
sqrt()
select fweight,sqrt(fweight) from t_person
4. 求随机数
rand() 支持有参数,也可以没参数
select rand()
select rand(123)
5.舍入到最大整数
ceiling()
select fname,fweight,ceiling(fweight),ceiling(fweight*-1) from t_person
6.舍入到最小整数
floor()
select fname,fweight,floor(fweight),floor(fweight*-1) from t_person
7.四舍五入
round()
round(m,d) m为待进行四舍五入的数值,d为计算精度,也就是四舍五入时保留的小数位数
d为0表示不保留小数位,d为负值表示在整数部分进行四舍五入。
select fname,fweight,round(fweight,1),round(fweight*-1,0),round(fweight,-1) from t_person
8.求正弦值
sin()
select fname,fweight,sin(fweight)from t_person
9.求余弦值
cos()
select fname,fweight,cos(fweight) from t_person
10.求反正弦
asin()
select fname,fweight,asin(1/fweight) from t_person
11.求反余弦
acos()
select fname,fweight,acos(1/fweight) from t_person
12.求正切值
tan()
select fname,fweight,tan(fweight) from t_person
13.求反正切值
atan()
select fname,fweight,atan(fweight) from t_person
14.求两个变量的反正切
atn2(x,y) 类似于计算y/x的反正切
select fname,fweight,atn2(fweight,2) from t_person
15.求余切
cot()
select fname,fweight,cot(fweight) from t_person
16.求圆周率π值
pi()
select fname,fweight,fweight*pi(),pi() from t_person
17.弧度制转换为角度制
degrees() 结果的精确度与参数有关
select degrees(pi()),degrees(3.0),degrees(3)
18.角度制转换为弧度制
radians() 结果的精确度与参数有关
select radians(180),radians(180.0)
19.求符号
sign() 返回一个数值的符号,如果数值大于0则返回1,
如果数值等于0则返回0,如果数值小于0则返回-1.
结果的精确度与参数有关
select fname,fweight-48.68,sign(fweight-48.68),sign(1),sign(1.000) from t_person
20.求整除余数 %
select fname,fweight,fweight%5 from t_person
21.求自然对数
log()
select fname,fweight,log(fweight),log(1.00) from t_person
22.求以10为底的对数
log10()
select fname,fweight,log10(fweight),log10(100) from t_person


ps:

主要参照《程序员的sql金典》
实例有所改动。
t_person表的创建
复制代码 代码如下:

create table t_person
(
fidnumber varchar(20),
fname varchar(20),
fbirthday datetime,
fregday datetime,
fweight numeric(10,2),
)

上一篇:

下一篇: