當我輸入驗證碼我不斷收到關於DepartmentName
「無效的標識符」:無效的ID查詢
SELECT LastName "Last Name", Gender "Gender"
FROM Employee
WHERE DepartmentName =
(SELECT DepartmentName FROM Department WHERE DepartmentName = 'Radiology');
任何幫助表示讚賞!
當我輸入驗證碼我不斷收到關於DepartmentName
「無效的標識符」:無效的ID查詢
SELECT LastName "Last Name", Gender "Gender"
FROM Employee
WHERE DepartmentName =
(SELECT DepartmentName FROM Department WHERE DepartmentName = 'Radiology');
任何幫助表示讚賞!
如果在創建表的時候在列名中有雙引號(比如說「DepartmentName」),那麼在選擇查詢中也應該有帶雙引號的列。
如果使用Where DepartmentName
,你會得到一個錯誤ORA-00904-無效標識符
因此,爲了避免錯誤,你必須使用WHERE「DepartmentName的」
我要去猜測其意圖是這樣的:
SELECT e.LastName as "Last Name", e.Gender as "Gender"
FROM Employee e
WHERE e.DepartmentId = (SELECT d.DepartmentId
FROM Department d
WHERE d.DepartmentName = 'Radiology'
);
也就是說,你想這兩個表連接的某種id
。如果您在Employee
有DepartmentName
,你會這樣寫:
SELECT e.LastName as "Last Name", e.Gender as "Gender"
FROM Employee e
WHERE e..DepartmentName = 'Radiology';
否「加盟」是必要的。
爲什麼這會被降低? –
可能性是部門名稱未存儲在employee表中,但部門表中某行的某個「外鍵」是。因此,您可以加入這兩個表格
SELECT e.LastName as "Last Name", e.Gender as "Gender"
FROM Employee e
INNER JOIN Department d ON e.DepartmentId = d.id -- guessed this column name
WHERE d.DepartmentName = 'Radiology'
如果遇到連接或IN()的選擇,請使用連接。
你確定'DepartmentName'存在嗎?你是否在正確的範圍內?你可能需要一個'[USE]'來確定嗎? – tmwoods
分享您的表格說明 – Valli
請閱讀並按照[mcve]進行操作。你的問題缺乏關鍵信息。 – philipxy