日期:2014-05-16  浏览次数:20685 次

求百分比的问题
select SUM(case when isnull(t3.BAG16,'0')<>'0' then 1 else 0 end )as jiyao,
COUNT(1) as heji
 from V_VAJ5 t1 join BBY1 t2 on t1.BBY05=t2.BBY05 join BAG1 t3 on t2.BBY01=t3.BBY01
 where t1.VAJ46 between '2014-01-01' and '2014-01-30'


----------------------------------------
需要得到jiyao/heji*100+'%'的值
------解决方案--------------------
引用:
jiyao的值是:25417
heji的值是:65122
1楼和3楼的sql计算出来的值都是0%和0.00%


改成这样:
select * , cast(cast(jiyao*1.0/heji*100.0 as numeric(10,2)) as varchar)+'%' as '百分比' from (
select SUM(case when isnull(t3.BAG16,'0')<>'0' then 1 else 0 end )as jiyao,
COUNT(1) as heji
 from V_VAJ5 t1 join BBY1 t2 on t1.BBY05=t2.BBY05 join BAG1 t3 on t2.BBY01=t3.BBY01
 where t1.VAJ46 between '2014-01-01' and '2014-01-30') a