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