我一直得到一个"无效的标识符"在我输入此代码时DepartmentName
:
SELECT LastName "Last Name", Gender "Gender"
FROM Employee
WHERE DepartmentName =
(SELECT DepartmentName FROM Department WHERE DepartmentName = 'Radiology');
感谢任何帮助!
答案 0 :(得分:0)
如果在创建表时你的列名中有双引号(说“DepartmentName”),那么你也应该在select query中有双引号的列。
如果您使用Where DepartmentName
,您将收到错误ora-00904-invalid-identifier
因此,为避免错误,您必须使用WHERE“DepartmentName”
答案 1 :(得分:0)
我猜这个意图是这样的:
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
上连接这两个表。如果DepartmentName
中有Employee
,您只需写:
SELECT e.LastName as "Last Name", e.Gender as "Gender"
FROM Employee e
WHERE e..DepartmentName = 'Radiology';
不需要“加入”。
答案 2 :(得分:0)
部门的名称可能不存储在员工表中,但有些"外键"在Department表中的一行是。因此,您将加入这两个表
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()的选择,请使用连接。