-2

我正在尝试运行此查询,但不知何故底部标签 B 不起作用。

我是甲骨文的新手,我只是看不出有什么问题。谁能帮帮我吗?将不胜感激。

当销售人员未与之绑定时,它不会返回任何数据。无论如何,这仍应返回有关基本客户的信息。

SELECT DISTINCT X.ship_sales_representative_id,
                X.ship_sales_representative_name,
                X.ship_sales_regional_name,
                X.ship_sales_regional_head,
                B.bl_customer_representative_id,
                X.sp_customer_representative_id,
                B.bill_customer_id,
                X.ship_customer_id,
                B.bill_customer_address_suffix,
                X.ship_customer_address_suffix,
                B.bill_customer_name,
                X.ship_customer_name,
                B.bill_customer_address,
                X.ship_customer_address,
                B.bill_customer_city,
                X.ship_customer_city,
                B.bill_customer_statecode,
                X.ship_customer_statecode,
                B.bill_customer_zipcode,
                X.ship_customer_zipcode,
                B.bill_customer_phonenumber,
                X.ship_customer_phonenumber,
                B.bill_customer_faxnumber,
                X.ship_customer_faxnumber,
                B.bill_customer_email,
                X.ship_customer_email,
                B.bill_customer_contact,
                X.ship_customer_contact
FROM   (SELECT DISTINCT S.rep_id      Ship_Sales_Representative_ID,
                        S.rep_name    Ship_Sales_Representative_Name,
                        S.reg_name    Ship_Sales_Regional_Name,
                        S.reg_head    Ship_Sales_Regional_Head,
                        C.rep_id      Sp_Customer_Representative_ID,
                        C.cust_id     Ship_Customer_ID,
                        C.addr_suffix Ship_Customer_Address_Suffix,
                        C.name        Ship_Customer_Name,
                        C.addr_ln_1   Ship_Customer_Address,
                        C.city        Ship_Customer_City,
                        C.state_cd    Ship_Customer_StateCode,
                        C.zip_cd      Ship_Customer_Zipcode,
                        C.phone_nbr   Ship_Customer_PhoneNumber,
                        C.fax_nbr     Ship_Customer_FaxNumber,
                        C.email       Ship_Customer_Email,
                        C.contact     Ship_Customer_Contact
        FROM   mdw.customer C,
               mdw.sales_org S
        WHERE  C.rep_id = To_char(S.rep_id, 'FM000000')
               AND C.cust_id = v_cust_id
               AND C.addr_suffix = v_addr_suffix) X,
       (SELECT DISTINCT C.rep_id      Bl_Customer_Representative_ID,
                        C.cust_id     Bill_Customer_ID,
                        C.addr_suffix Bill_Customer_Address_Suffix,
                        C.name        Bill_Customer_Name,
                        C.addr_ln_1   Bill_Customer_Address,
                        C.city        Bill_Customer_City,
                        C.state_cd    Bill_Customer_StateCode,
                        C.zip_cd      Bill_Customer_Zipcode,
                        C.phone_nbr   Bill_Customer_PhoneNumber,
                        C.fax_nbr     Bill_Customer_FaxNumber,
                        C.email       Bill_Customer_Email,
                        C.contact     Bill_Customer_Contact
        FROM   mdw.customer C
        WHERE  C.cust_id = v_cust_id
               AND C.addr_suffix = '0001') B; 
4

1 回答 1

0

您可能希望在查询末尾添加:

WHERE X.REP_ID = B.REP_ID              

(并删除第一个DISTINCT)或其他条件,JOIN否则此查询将返回所有记录X组合B

既然你在寻找

AND   C.CUST_ID     =v_Cust_ID

你应该在加入中使用它!

由于您不确定信息是否存在,X您应该使用您可以通过以下方式LEFT JOINXOracle 中执行的操作:

WHERE B.CUST_ID = X.CUST_ID(+)
于 2013-10-21T18:46:43.547 回答