执行除法的时候,为什么输出结果为空,而不是18啊:select 1800/(select case
when sum(t.nonenum) = '' then 100
when sum(t.nonenum) = 0 then 100
else 100 end
from T_SEARCHNONE_COUNT@TO_31 t
where t.staffno = '7449'
and t.logdate >= to_date('2013-3-27', 'yyyy-mm-dd')
and t.logdate < to_date('2013-3-28', 'yyyy-mm-dd'))
Rate
from dual w;
oracle除法
when sum(t.nonenum) = '' then 100
when sum(t.nonenum) = 0 then 100
else 100 end
from T_SEARCHNONE_COUNT@TO_31 t
where t.staffno = '7449'
and t.logdate >= to_date('2013-3-27', 'yyyy-mm-dd')
and t.logdate < to_date('2013-3-28', 'yyyy-mm-dd'))
Rate
from dual w;
oracle除法
select 1800/(select case
when sum(t.nonenum) is null then 100
when sum(t.nonenum) = 0 then 100
else 100 end
from T_SEARCHNONE_COUNT@TO_31 t
where t.staffno = '7449'
and t.logdate >= to_date('2013-3-27', 'yyyy-mm-dd')
and t.logdate < to_date('2013-3-28', 'yyyy-mm-dd'))
Rate
from dual w;
你的查询结果为空,就是因为where条件没有符合数据,而用到了case when sum(t.nonenum) = '' then 100 导致 结果不是期待的100 而是null。 测试一下明确了。 select case when sum(null) = '' then 100 end from dual; 返回null;
select case when sum(null) is null then 100 end from dual; 返回100; 还有就是对一些查询有疑问的时候可以通过dual表测试一下 ,特别是涉及null的时候,希望能帮到你,好运。