2 个数字相除返回 0 [英] Dividing 2 numbers returns 0
本文介绍了2 个数字相除返回 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将 2 个计数相除以返回一个百分比.
I'm trying to divide 2 counts in order to return a percentage.
以下查询返回0
:
select (
(select COUNT(*) from saxref..AuthCycle
where endOfUse is null and addDate >= '1/1/2014') /
(select COUNT(*) from saxref..AuthCycle
where addDate >= '1/1/2014')
) as Percentage
我应该申请演员表吗?
推荐答案
我会用两个sum
来做不同的事情:
I would do it differently, using two sum
s:
select sum
( case
when endOfUse is null and addDate >= '1/1/2014'
then 1
else 0
end
)
* 100.0 -- if you want the usual 0..100 range for percentages
/
sum
( case
when addDate >= '1/1/2014'
then 1
else 0
end
)
percentage
from saxref..AuthCycle
这篇关于2 个数字相除返回 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文