我有 2 张桌子,分配和员工。它们通过 EmployeeNumber 链接,而 HoursWorked 是存储在 assignment 中的一个属性。我已经尝试过了,我得到一个错误,说子查询返回超过 1 行。我究竟做错了什么:
SELECT e.FirstName, e.LastName
FROM employee e
WHERE (
SELECT a.HoursWorked
FROM assignment a
WHERE a.HoursWorked > 50);
看起来你正在尝试做这样的事情:
SELECT e.FirstName, e.LastName
FROM employee
JOIN assignment on employee.EmployeeNumber = assignment.EmployeeNumber
WHERE assignment.HoursWorked > 50;
SELECT e.FirstName, e.LastName
FROM employee e
WHERE e.EmployeeNumber IN (
SELECT EmployeeNumber
FROM assignment a
WHERE a.HoursWorked > 50);