【发布时间】:2017-04-27 02:51:35
【问题描述】:
我做了一个查询,其中使用了 3 个表。第一个表具有我需要的所有所需名称。第 2 和第 3 表给了我那些有一些账单金额的名字。但我也需要第一个表中的所有名称。
SELECT a.name,
nvl(c.bill_amount,0)
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
AND B.email = C.email
where b.status = 'YES'
and a.VALID = 'Y';
现在,表 b 和 c 给了我有限数量的名字,让我说 5 是哪张账单。但在 table_1 中,有 10 个名称。我想在他们的名字上也显示 0 bill_amount。我正在使用 Oracle。
【问题讨论】:
-
把 where 改成这个; 'WHERE (b.status = 'YES' OR b.status IS NULL)' 或将其放入连接中(取出 where 子句)'AND b.status = 'YES''
标签: sql database join outer-join