修改腳本啊!

網(wǎng)站建設哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、微信平臺小程序開發(fā)、集團企業(yè)網(wǎng)站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了長汀免費建站歡迎大家使用!
--method?1?
declare?@a?int?---分子
declare?@b?int?---分母
select??case??when?@b=0?then?NULL?else?@a/@b?end??as?[a除以b]
--method?2
declare?@a?int?---分子
declare?@b?int?---分母
select?@a/nullif(@b,0)?as?[a除以b]
在零之前判斷以下,避免分母為零
sqlserver避免遇零除錯
在oracle中,你也可以采用上述類似的方法,處理相關的錯誤信息,請試一試,
如有疑問,及時溝通!
這樣一個情況
select * from a where c0 and (b/c)0.5 and (b/c)0.6
這樣一條語句,由于b,c是二個數(shù)值列,里面記錄的是金額,而c 的話有可能為0,那么這時我們雖然加上了c0這個條件,卻仍有可能 出現(xiàn) 遇到以零作除數(shù)錯誤 這個錯誤.
解決這個問題,有二種方法,一種是自己加個函數(shù) 發(fā)覺c=0時,將c改成1 ;如 b/checkdata(c)0.6
另一種方式 則是使用sqlserver 的選項來禁止出現(xiàn)以零除的錯誤中斷,讓而讓其為null
set ansi_warnings off
SET ARITHABORT off
SET ARITHIGNORE on
select * from a where c0 and (b/c)0.5 and (b/c)0.6
如果一來,當執(zhí)行時,遇到某條記錄里為0時,則二數(shù)相除為null,而null0.6這個是不成立的,從而達到了作為條件的目的.
先將分子或分母或兩個都轉化成8小數(shù)精度以上的類型,decimal,numeric,float 都可以。
然后做除法計算,將計算結果轉化為8位小數(shù)。
select convert(decimal(18,8), convert(decimal(18,8),1)/3)
select convert(decimal(18,8), 1/convert(decimal(18,8),3))
select CONVERT(decimal(18,8), convert(float,1)/3)
select CONVERT(decimal(18,8), 1/convert(float,3))
1.round() 函數(shù)是四舍五入用,第一個參數(shù)是我們要被操作的數(shù)據(jù),第二個參數(shù)是設置我們四舍五入之后小數(shù)點后顯示幾位。
2.numeric 函數(shù)的2個參數(shù),第一個表示數(shù)據(jù)長度,第二個參數(shù)表示小數(shù)點后位數(shù)。
例如:
select cast(round(12.5,2) as numeric(5,2)) 結果:12.50
select cast(round(12.555,2) as numeric(5,2)) 結果:12.56
select cast(round(122.5255,2) as numeric(5,2)) 結果:122.53
select cast(round(1222.5255,2) as numeric(5,2)) 結果:報錯了! 原因是:1222.5255,整數(shù)位是4,小數(shù)位是2,加起來4+2=6,超出了numeric設置的5位,所以為了保險,可以增減numeric的參數(shù),例如numeric(20,2)。
trunc(45.923,1) 按指定精度截斷十進制數(shù) 結果:45.9 此為oracle函數(shù)
mod(1600,300) 求除法余數(shù) 結果:100
abs(numeric_expr) 求絕對值
ceiling(numeric_expr) 取大于等于指定值的最小整數(shù)
avg(numeric_expr)取平均數(shù)
exp(float_expr) 取指數(shù)
floor(numeric_expr) 小于等于指定值得最大整數(shù)
pi() 3.1415926.........
power(numeric_expr,power) 返回power次方
rand([int_expr]) 隨機數(shù)產(chǎn)生器
round(numeric_expr,int_expr) 安int_expr規(guī)定的精度四舍五入
sign(int_expr) 根據(jù)正數(shù),0,負數(shù),,返回+1,0,-1
sqrt(float_expr) 平方根
select (select count(*) as y from t where s='b')
(select count(*) as n from t where s!='b')
在SqlServer默認當做int類型,兩個int變量相除得到的還是個int類型 ,所以只要把其中一個改成小數(shù)類型的就可以得到你要的結果了。
除法運算
一款簡單的除法運算題目,小朋友們懂的做,很簡單的除法運算,小朋友們來挑戰(zhàn)一下
運算是一種游戲,適用于小孩子對于數(shù)學的理解。
分享標題:除法sqlserver,除法怎么算
網(wǎng)頁鏈接:http://chinadenli.net/article9/dseppih.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供關鍵詞優(yōu)化、標簽優(yōu)化、網(wǎng)站維護、虛擬主機、外貿(mào)網(wǎng)站建設、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)