Oracle 当前条件没有返回数据,如何让它某个字段返回一个0? 50
selectt1.curr_dealcurr_deal1,t1.kpi_valuevalue1,t2.curr_dealcurr_deal2,decode(t2.kpi_...
select t1.curr_deal curr_deal1,
t1.kpi_value value1,
t2.curr_deal curr_deal2,
decode(t2.kpi_value,null,0,t2.kpi_value) value2,
t3.curr_deal curr_deal3,
decode(t3.kpi_value,null,0,t3.kpi_value) value3
from (select curr_deal, dms_cl, kpi_id, sum(kpi_value) kpi_value
from LV1 where kpi_id = 159
group by curr_deal, dms_cl, kpi_id) t1,
(select curr_deal, dms_cl, kpi_id, sum(kpi_value) kpi_value
from LV1 where kpi_id = 159
group by curr_deal, dms_cl, kpi_id) t2,
(select curr_deal, dms_cl, kpi_id, sum(kpi_value) kpi_value
from LV1 where kpi_id = 159
group by curr_deal, dms_cl, kpi_id) t3
where t1.kpi_id = t2.kpi_id
and t1.kpi_id = '159'
and t1.kpi_id = t3.kpi_id
and t1.dms_cl = t2.dms_cl
and t1.dms_cl = '1010259'
and t1.dms_cl = t3.dms_cl
and t1.curr_deal between 20141107 and 20141202
and t2.curr_deal =
to_char(to_date(t1.curr_deal, 'yyyymmdd') - 1, 'yyyymmdd')
--and t3.curr_deal =
to_char(add_months(to_date(t1.curr_deal, 'yyyymmdd'), -1),
'yyyymmdd')
order by t1.curr_deal) t;
这是我的sql,求助各位,三张表联查,日期分别为今日,昨日,上月今日,但是有的时候昨日和上月没有数据的话,今天的值也查不出来了,所以想让没有数据的时候值返回一个0(没数据的时候是一整条都没有,不单是值的字段没有)。nvl也试过了,没成功。。谢谢各位!!! 展开
t1.kpi_value value1,
t2.curr_deal curr_deal2,
decode(t2.kpi_value,null,0,t2.kpi_value) value2,
t3.curr_deal curr_deal3,
decode(t3.kpi_value,null,0,t3.kpi_value) value3
from (select curr_deal, dms_cl, kpi_id, sum(kpi_value) kpi_value
from LV1 where kpi_id = 159
group by curr_deal, dms_cl, kpi_id) t1,
(select curr_deal, dms_cl, kpi_id, sum(kpi_value) kpi_value
from LV1 where kpi_id = 159
group by curr_deal, dms_cl, kpi_id) t2,
(select curr_deal, dms_cl, kpi_id, sum(kpi_value) kpi_value
from LV1 where kpi_id = 159
group by curr_deal, dms_cl, kpi_id) t3
where t1.kpi_id = t2.kpi_id
and t1.kpi_id = '159'
and t1.kpi_id = t3.kpi_id
and t1.dms_cl = t2.dms_cl
and t1.dms_cl = '1010259'
and t1.dms_cl = t3.dms_cl
and t1.curr_deal between 20141107 and 20141202
and t2.curr_deal =
to_char(to_date(t1.curr_deal, 'yyyymmdd') - 1, 'yyyymmdd')
--and t3.curr_deal =
to_char(add_months(to_date(t1.curr_deal, 'yyyymmdd'), -1),
'yyyymmdd')
order by t1.curr_deal) t;
这是我的sql,求助各位,三张表联查,日期分别为今日,昨日,上月今日,但是有的时候昨日和上月没有数据的话,今天的值也查不出来了,所以想让没有数据的时候值返回一个0(没数据的时候是一整条都没有,不单是值的字段没有)。nvl也试过了,没成功。。谢谢各位!!! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询