标识符错误的麻烦

时间:2014-05-04 23:41:43

标签: sql oracle

我需要列出2013年1月26日当天或之前所有订单的订单ID,订单日期,客户ID,客户名,客户姓名和客户电话号码。按订单日期排序,然后按客户ID排序,两者均按升序排序。将日期格式设置为“mm-dd-yyyy”并使用以下列标题:OrderID,OrderDate,CustID,CustFirstName,CustLastName,CustPhone。

但是我收到一条错误说“ORD。”CUST_ID“:标识符无效

这是我的代码

 SELECT ORD.Order_ID as OrderID, to_char(Order_Date,'mm-dd-yyyy') as OrderDate, C.Cust_ID as 
 CustID, Cust_FName as CustFirstName, Cust_LName as CustLastName, Cust_Phone as CustPhone
 FROM ORDER_arb ORD, CUSTOMER_arb C
 INNER JOIN ORDER_arb ON C.Cust_ID = ORD.Cust_ID
 WHERE Order_Date <= '26-JAN-13'
 ORDER BY Order_Date, Cust_ID;

感谢您的帮助,谢谢

2 个答案:

答案 0 :(得分:1)

您正在混合隐式和显式join语法。我认为问题是你在ORDER_ARB子句中有两次FROM表。试试这个:

SELECT ORD.Order_ID as OrderID, to_char(ORD.Order_Date, 'mm-dd-yyyy') as OrderDate,
       C.Cust_ID as CustID, C.Cust_FName as CustFirstName, C.Cust_LName as CustLastName,
       C.Cust_Phone as CustPhone
FROM CUSTOMER_arb C INNER JOIN
     ORDER_arb ORD
     ON C.Cust_ID = ORD.Cust_ID
WHERE ORD.Order_Date <= '26-JAN-13'
ORDER BY ORD.Order_Date, C.Cust_ID;

答案 1 :(得分:0)

您的查询中的问题似乎就在这里

 FROM ORDER_arb ORD, CUSTOMER_arb C   INNER JOIN 
   ORDER_arb    -- no alias here 
      ON C.Cust_ID = ORD.Cust_ID ---   here you have given ORD as alias 

ORDER_arb 表提供不同的别名,然后尝试

这可能对您有帮助,

SELECT ORD.Order_ID as OrderID, to_char(Order_Date,'mm-dd-yyyy') as OrderDate, C.Cust_ID as 
CustID, Cust_FName as CustFirstName, Cust_LName as CustLastName, Cust_Phone as      CustPhone
FROM ORDER_arb ORD, CUSTOMER_arb C
INNER JOIN 
ORDER_arb  OR_AB ON C.Cust_ID = OR_AB.Cust_ID
 WHERE Order_Date <= '26-JAN-13'
  ORDER BY Order_Date, Cust_ID;