在JOIN語句中的子查詢中選擇特定字段時,使用點符號來引用table.field_name,但是,在第一個JOIN中使用另一個子查詢JOIN時要執行什麼操作?如何在JOIN中的JOIN中引用字段?
我的JOIN瓦特/例如JOIN:
JOIN (SELECT
BUDGET.protocol_id, BUDGET.completed_date,
CONTRACT.completed_date,
REQUEST.completed_date,
RECEIVE.completed_date,
PC.completed_date,
FC.completed_date,
MGR.completed_date
FROM (SELECT completed_date, task_list_id, protocol_id FROM task WHERE task_name LIKE 'Budget%') BUDGET
JOIN (SELECT completed_date, task_list_id, protocol_id FROM task WHERE task_name LIKE 'Contract%') CONTRACT
ON BUDGET.protocol_id = CONTRACT.protocol_id
AND BUDGET.task_list_id = CONTRACT.task_list_id
JOIN (SELECT completed_date, task_list_id, protocol_id FROM task WHERE task_name LIKE 'Request%') REQUEST
ON BUDGET.protocol_id = REQUEST.protocol_id
AND BUDGET.task_list_id = REQUEST.task_list_id
JOIN (SELECT completed_date, task_list_id, protocol_id FROM task WHERE task_name LIKE 'Protocol%') PC
ON BUDGET.protocol_id = PC.protocol_id
AND BUDGET.task_list_id = PC.task_list_id
JOIN (SELECT completed_date, task_list_id, protocol_id FROM task WHERE task_name LIKE 'Financials%') FC
ON BUDGET.protocol_id = FC.protocol_id
AND BUDGET.task_list_id = FC.task_list_id
JOIN (SELECT completed_date, task_list_id, protocol_id FROM task WHERE task_name LIKE 'Manager%') MGR
ON BUDGET.protocol_id = MGR.protocol_id
AND BUDGET.task_list_id = MGR.task_list_id
JOIN (SELECT completed_date, task_list_id, protocol_id FROM task WHERE task_name LIKE 'Receive%') RECEIVE
ON BUDGET.protocol_id = RECEIVE.protocol_id
AND BUDGET.task_list_id = RECEIVE.task_list_id
) TASK ON PCL.protocol_id = TASK.BUDGET.protocol_id
我一直在嘗試與子查詢要做的就是選擇特定的任務完成日期,所以在SELECT語句我的直覺是使用TASK.BUDGET.completed_date,用於每個任務。然而,我得到一個ORA-00918:含糊不清的列,因此似乎有什麼問題都用completed_date
如果你運行你發佈的所有代碼(減去'JOIN('開始它),它運行嗎?它對我來說看起來很好,所以我的猜測是你的錯誤是在外部選擇或分組。 –
The子查詢的自我肯定運行,儘管緩慢。問題來了,當我在主要查詢SELECT語句中添加: 'TASK.BUDGET.completed_date, TASK.CONTRACT.completed_date, TASK.REQUEST.completed_date, TASK.RECEIVE。 completed_date, TASK.PC.completed_date,\t TASK.FC.completed_date, TASK.MGR.completed_date」 ,其拋出00918誤差 – Dan
)TASK ON PCL.pro tocol_id = TASK.BUDGET.protocol_id - 其中是哪個開放式支架?每個子查詢都被認爲是最好的,因爲它是自己的表......它中的所有東西都是自包含的,不能引用它之外的任何對象。 task.budget.completed_date永遠不會是正確的引用。編輯:如果你沒有那個任務參考,這是有效的,不是?你會想要在每個子查詢中別名,以避免混淆(SELECT completed_date as budget_completed_date)或類似的東西 – Twelfth