标识符错误的麻烦
Posted
技术标签:
【中文标题】标识符错误的麻烦【英文标题】:Trouble With Identifier Error 【发布时间】:2014-05-04 23:41:42 【问题描述】:我需要列出 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;
感谢您的帮助,谢谢
【问题讨论】:
Oracle...我很抱歉让 mysql 成为标签。 【参考方案1】:您正在混合隐式和显式 join
语法。我认为问题在于您在FROM
子句中有两次ORDER_ARB
表。试试这个:
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;
【讨论】:
好主意-但我仍然在 Cust_ID 下收到“列不明确定义”错误【参考方案2】:您的查询中的问题似乎在这里
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;
【讨论】:
以上是关于标识符错误的麻烦的主要内容,如果未能解决你的问题,请参考以下文章
麻烦:'const int * const & alias_for_ptr = ptr;',为啥两个标识符有不同的值?