Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 左连接不';t work-它忽略左表的记录_Sql_Oracle - Fatal编程技术网

Sql 左连接不';t work-它忽略左表的记录

Sql 左连接不';t work-它忽略左表的记录,sql,oracle,Sql,Oracle,我有三张桌子 桌上顾客 ID NUMBER NAME -------------------------------------- 1 12345 Apple 2 23456 Orange 3 25896 Banana 表帐户 ID CUST_NUMBR TYPE BILLING_FK ------------------------------------- 1 12345 B 9876 2 23456

我有三张桌子

桌上顾客

ID NUMBER NAME
--------------------------------------
1  12345  Apple
2  23456  Orange
3  25896  Banana
表帐户

 ID    CUST_NUMBR  TYPE    BILLING_FK
 -------------------------------------
 1     12345        B      9876
 2     23456        R      8765
 3     25896        R      7654
表账单

 ID    Start_Date  End_Date 
 -------------------------------------
 1     BLAH       BLAH       
 2     BLAH       BLAH             
 3     BLAH       BLAH       
关系

  CUSTOMER.NUMBER = ACCOUNT.CUST_NUMBR
  ACCOUNT.BILLING_FK  = BILLING.ID
有时找不到客户的帐户,在这种情况下,开始日期必须为空

如果我尝试使用left join,如果没有帐户,我就看不到客户

 select name,number,start_date
 from customer left join account on customer.number = account.cust_number,
 billing
 where account.billing_fk = billing.id

如果没有该客户的帐户,如何将开始日期设置为null。

由于where子句中的以下语句,该设置不起作用:

account.billing_fk = billing.id

尝试将其移动到
左连接部分

由于where子句中的以下语句,它无法工作:

account.billing_fk = billing.id

尝试将其移动到
左连接部分

您的条件
account.billing\u fk=billing.id
将您的
左连接
转换为
内部连接
。它几乎消除了所有
NULL
条目

select name,number,start_date
from customer 
left join account on customer.number = account.cust_number
left join billing on account.billing_fk = billing.id

您的条件
account.billing\u fk=billing.id
将您的
左连接
转换为
内部连接
。它几乎消除了所有
NULL
条目

select name,number,start_date
from customer 
left join account on customer.number = account.cust_number
left join billing on account.billing_fk = billing.id