sql server中除法,會遇到除數為0的情況,且保留兩位小數,寫法如下:
select case when num=0 then 0 else convert(decimal(18,2),210.343/num) end as 結果 from tabnumber
select
[carrier] as '承運人分組',
count(*) as '張數',
'0' as '出票效率',
sum(cast(sumprice as int)) as '票面價',
sum(cast([taxprice] as int)) as '基建費',
sum(cast([oilprice] as int)) as '燃油費',
sum(cast(sumprice as int) - cast([flightback] as int)) as '實收費'
from [order_flightdetail] group by [carrier] order by count(*) desc
select
[carrier] as '承運人分組',
count(*) as '張數',
'0' as '出票效率',
sum(convert(decimal(18,2),sumprice)) as '票面價',
sum(convert(decimal(18,2),[taxprice])) as '基建費',
sum(convert(decimal(18,2),[oilprice])) as '燃油費',
sum(convert(decimal(18,2),sumprice) - convert(decimal(18,2),[flightback])) as '實收費'
from [order_flightdetail] where [carrier] <>'' group by [carrier] order by count(*) desc
Sql 保留兩位小數
sql中欄位保留兩位小數 使用round 函式,如round number,2 其中引數2表示保留兩位有效數字,但是只負責四捨五入到兩位小數,但是不負責截斷 例如round 3.141592653,2 結果為3.140000000 使用convert decimal 10,2 number 實現轉換...
保留兩位小數
1.只要求保留n位不四捨5入 float f 0.55555f int i int f 100 f float i 1.0 100 2.保留n位,四捨五入 decimal d decimal.round decimal.parse 0.55555 2 3.保留n位四捨五入 math.round 0....
保留兩位小數
num 10.4567 第一種 利用round 對浮點數進行四捨五入 echo round num,2 第二種 利用sprintf格式化字串 format num sprintf 2f num echo format num 第三種 利用千位分組來格式化數字的函式number format echo...