我遇上一个奇怪的问题:
SELECT
*,
case when tt_trans =0 then 0 else vip_trans/tt_trans end as present_vip_trans
FROM
(
select
a.store_code_id,
sum(s.transactions) as tt_trans,
sum(case when v.vipcode_id is not null then s.transactions end) as vip_trans
。。。。。。
结果:

为什么 tt_ trans 和 vip_trans 都有数且不为 0,但 case when tt_trans =0 then 0 else vip_trans/tt_trans end 的结果会是 0 呢?
然后我把 null 替换成 0,
SELECT
*,
case when tt_trans =0 then 0 else vip_trans/tt_trans end as present_vip_trans
FROM
(
select
a.store_code_id,
isnull(sum(s.transactions),0) as tt_trans,
isnull(sum(case when v.vipcode_id is not null then s.transactions end),0) as vip_trans
。。。。。。
结果:

貌似 tt_ trans 和 vip_trans 不管是什么数都被看做 0 呢,
小弟不才被这问题搞得哭了几天了,求各位英雄出手帮帮忙。谢谢啦!

------解决方案--------------------
试试isnull(sum(s.transactions),0)改成sum(isnull(s.transactions,0))