日期:2014-05-19  浏览次数:20518 次

简单的除法运算
表中有两列,我想用第一列除第二列,第二列中有0,并且将结果保存为百分数的形式可以吗,如3.2%,谢谢各位!

------解决方案--------------------
为0的怎么处理?
select case when Col2 <> 0 then ltrim(round(Col1*1.00/Col2,2))+ '% ' else '0 ' end result from [Table]
------解决方案--------------------
select case when 第二列 <> 0 then cast(round(((第一列*1.0)/第二列) *100,2) as varchar)+ '% ' else '0 ' end from 表
------解决方案--------------------
select 百分数=case when 第二列=0 then 0 else cast(cast(第一列 as decimal(9,2)) /cast(第二列 as decimal(9,2))*100 as varchar(20))+ '% ' end from 表