Home  >  Article  >  Database  >  mssql server 数学函数实例(1/2)

mssql server 数学函数实例(1/2)

WBOY
WBOYOriginal
2016-06-07 17:47:12819browse

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() 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn