我正在尝试在Oracle SQL Developer中将Customer_ID上具有Order_Header的客户加入,并且即使两个表在两个表中都存在列的情况下也遇到“无效标识符”错误。
Select C.customer_name, Order_Header.total_sales, order_detail.quantity,
C.customer_ID
From Customers C
Join Order_Header Using (Customer_ID);
答案 0 :(得分:0)
您可以运行以下内容吗?
Select C.* From Customers C
和
Select O.* From Order_Header O
我想您可能缺少架构名称select t.* from schema.table
。
答案 1 :(得分:0)
阅读上面的评论,您一直在说
“订单详细信息”部分要进行第三次连接,但是即使删除了该部分,也存在相同的错误。
什么是“那部分”?如果您的意思是与ORDER_DETAILS
表进行联接,则应添加而不是删除“部分”。或者,您应删除ORDER_DETAILS
子句中不存在的属于FROM
表的列。
如果提供表的描述,将会有所帮助;我使用最小列集自己创建了它们,以便查询正常工作。看看。
SQL> -- CUSTOMERS: column names taken from your query
SQL> create table customers
2 (customer_id number constraint pk_cust primary key,
3 customer_name varchar2(20));
Table created.
SQL> -- ORDER_HEADER: ORDER_ID must exist in order to join it with ORDER_DETAIL
SQL> create table order_header
2 (order_id number constraint pk_oh primary key,
3 customer_id number constraint fk_oh_cust references customers (customer_id),
4 total_sales number);
Table created.
SQL> -- ORDER_DETAIL: I added ORDER_ID as a reference to ORDER_HEADER
SQL> create table order_detail
2 (order_id number constraint fk_od_oh references order_header (order_id),
3 quantity number);
Table created.
使用所有3个表的 full 查询将如下所示:
SQL> select c.customer_name,
2 oh.total_sales,
3 od.quantity,
4 c.customer_id
5 from customers c join order_header oh on oh.customer_id = c.customer_id
6 join order_detail od on od.order_id = oh.order_id;
no rows selected
SQL> -- query you wrote, slightly formatted:
SQL> Select C.customer_name,
2 Order_Header.total_sales,
3 order_detail.quantity,
4 C.customer_ID
5 From Customers C
6 Join Order_Header Using (Customer_ID);
C.customer_ID
*
ERROR at line 4:
ORA-25154: column part of USING clause cannot have qualifier
这意味着您应该删除第4行中的“ C.
”:
SQL> Select C.customer_name,
2 Order_Header.total_sales,
3 order_detail.quantity,
4 customer_ID
5 From Customers C
6 Join Order_Header Using (Customer_ID);
order_detail.quantity,
*
ERROR at line 3:
ORA-00904: "ORDER_DETAIL"."QUANTITY": invalid identifier
现在,您遇到另一个错误-您正在引用QUANTITY
子句中从未引用过的ORDER_DETAIL
列;因此-从FROM
中删除该列:
SELECT
或者,在SQL> Select C.customer_name,
2 Order_Header.total_sales,
3 -- order_detail.quantity,
4 customer_ID
5 From Customers C
6 Join Order_Header Using (Customer_ID);
no rows selected
子句中添加ORDER_DETAIL
,这将使您返回到我最初发布的查询。