相关子查询
相关(也称为同步或协调)子查询是嵌套查询,它们引用其外部查询的当前行:
SELECT EmployeeId
FROM Employee AS eOuter
WHERE Salary > (
SELECT AVG(Salary)
FROM Employee eInner
WHERE eInner.DepartmentId = eOuter.DepartmentId
)
子查询 SELECT
AVG(Salary) ...
是*相关的,*因为它从其外部查询引用 Employee
row eOuter
。