加入条件显示不恰当的结果

时间:2017-03-14 06:14:03

标签: database oracle join left-join where-clause

    SELECT   a.name,
             nvl(c.bill_amount,0),
             b.status
        FROM  table_1 a left outer join table_2 b
        ON  a.name = b.name and
           b.status = 'YES'
        left outer join table_3 c on B.phone_number = C.phone_number
             AND B.email = C.email
             where 
             a.VALID = 'Y';

我最近写了这个查询,条件是b.status ='是'在上面的查询中未满足,状态显示为NULL值。我想根据这个条件优化我的记录b.status =' yes'。

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

   SELECT  a.name, nvl(c.bill_amount,0), b.status
   FROM  table_1 a left outer join table_2 b
   ON  a.name = b.name
   left outer join table_3 c on b.phone_number = c.phone_number
   where 
   a.VALID = 'Y' and
   b.status = 'YES' and
   b.email = c.email