MSSQL SERVER 2005 數學函數整理
添加時間:2014-2-26 17:24:12
添加:
思海網絡
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),
)
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),
)
關鍵字:MSSQL、SERVER、數學函數
新文章:
- CentOS7下圖形配置網絡的方法
- CentOS 7如何添加刪除用戶
- 如何解決centos7雙系統后丟失windows啟動項
- CentOS單網卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗證詳解
- CentOS 7.1添加刪除用戶的方法
- CentOS查找/掃描局域網打印機IP講解
- CentOS7使用hostapd實現無AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網絡重啟出錯
- 解決Centos7雙系統后丟失windows啟動項
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統有什么不同呢
- Centos 6.6默認iptable規則詳解