我要执行如下的sql语句
select nvl(b.material_money,0)+nvl(c.ysk_money,0)-nvl(a.gathering_money,0) as money,
c.customer_id as customer_id from
(select nvl(sum(nvl(gathering_money,0)),0) as gathering_money,customer_id,seller_id from 
cs_gathering where customer_id='000742' and seller_id='0002025051' 
group by customer_id,seller_id) a,
(select nvl(sum(nvl(material_money,0)),0) 
as material_money from cs_bill_of_lading where customer_id='000742' 
and distill_man=(select seller from cs_seller where seller_id='0002025051') 
group by customer_id,distill_man) b, 
(select sum(nvl(ysk_money,0)) as ysk_money,customer_id,sell_id from customer_ysk 
where customer_id='000742' and sell_id='0002025051' group by customer_id,sell_id) c 
where c.sell_id=a.seller_id 
and c.customer_id = a.customer_id 
当其中某一张表中的customer_id='000742' and sell_id='0002025051'条件不成立时,就会没有返回值,只要当三张表都满足customer_id='000742' and sell_id='0002025051'条件时,才能得到我要的结果,请问如何做才能避免上面的问题

解决方案 »

  1.   

    条件中这样处理
    nvl(customer_id,'-1000')='000742'
      

  2.   

    请问楼上的能否解释一下
    nvl(customer_id,'-1000')='000742'
    是什么意思
      

  3.   

    外连接即可解决这个问题。
    先看看哪个表里面没有这样的记录,如a,b,c三个这样的表,如果c中没有这样的记录,就把where条件改为 where a.id=c.id(+) and b.id=c.id(+)即可解决。
      

  4.   

    where c.sell_id(+)=a.seller_id 
    and c.customer_id(+) = a.customer_id 
      

  5.   

    sum(nvl(ysk_money,0))   
    修改为以下:
    nvl(sum(ysk_money),0)
    把所有都修改为第二种形式吧