问题是:列出与拥有empno 77的员工Joe Bloggs在同一电影院工作的员工的员工详细信息。
SELECT *
FROM Employee
WHERE Cinema_no IN (SELECT Cinema_no
FROM Employee
WHERE Forename = 'Joe'
AND Surname = 'Bloggs')
AND Empno <> 77;
没有错误消息,但是不会返回与Joe Bloggs在同一电影院工作的员工?
答案 0 :(得分:1)
您的查询看起来还不错。我建议使用empno
而不是surname
/ forname
来识别员工。
SELECT *
FROM Employee
WHERE
Cinema_no IN (SELECT Cinema_no FROM Employee WHERE empno = 77)
AND empno <> 77;
另一种解决方案是使用联接
SELECT emp.*
FROM Employee emp
JOIN ( SELECT Cinema_no FROM Employee WHERE empno = 77) cin on emp.cinema_no = cin.cinema_no
WHERE emp.empno <> 77;
答案 1 :(得分:0)
Select *
from employee
where cinema_no in (select cimema_no
from employees
where emp_no = 77)
and emp_no <> 77;
您的查询非常好,直到您拥有该姓氏/姓氏为止,如下所示
SELECT *
FROM Employee
WHERE Cinema_no IN (SELECT Cinema_no
FROM Employee
WHERE UPPER(FORENAME) = UPPER('Joe')
AND UPPER(SURNAME) = UPPER('Bloggs'))
AND empno <> 77