如何修复Oracle Join中的“列定义不明确”

时间:2019-01-30 09:41:23

标签: sql database oracle

以下是我的代码最简洁。我不知道为什么我遇到这个问题。请协助我。

select cp.AMOUNT from customer_payee_transactions cp

LEFT OUTER JOIN merchant_transactions mt ON (cp.merchant_transaction_id = 
mt.merchant_transaction_id)

WHERE AMOUNT > 500 AND MODIFIED_DATETIME 
BETWEEN TO_DATE('27/01/2019 22:00:00', 'DD/MM/YYYY hh24:mi:ss') 
AND TO_DATE('27/01/2019 23:00:00', 'DD/MM/YYYY hh24:mi:ss');

请帮助我。 谢谢。

2 个答案:

答案 0 :(得分:2)

您需要在cpAMOUNT列之前定义MODIFIED_DATETIME,因为您已经为表定义了别名。

select cp.AMOUNT 
from customer_payee_transactions cp LEFT OUTER JOIN merchant_transactions mt 
ON cp.merchant_transaction_id = mt.merchant_transaction_id
WHERE cp.AMOUNT > 500 AND cp.MODIFIED_DATETIME 
BETWEEN TO_DATE('27/01/2019 22:00:00', 'DD/MM/YYYY hh24:mi:ss') 
AND TO_DATE('27/01/2019 23:00:00', 'DD/MM/YYYY hh24:mi:ss');

答案 1 :(得分:1)

您需要表别名name.column name

select cp.AMOUNT from customer_payee_transactions cp    
LEFT OUTER JOIN merchant_transactions mt ON (cp.merchant_transaction_id = 
mt.merchant_transaction_id)

WHERE cp.AMOUNT > 500 AND cp.MODIFIED_DATETIME 
BETWEEN TO_DATE('27/01/2019 22:00:00', 'DD/MM/YYYY hh24:mi:ss') 
AND TO_DATE('27/01/2019 23:00:00', 'DD/MM/YYYY hh24:mi:ss');

还在此列的MODIFIED_DATETIME之前放置表别名名称