子查询的正确语法和联接(如果有)是什么,该子查询将从雇员表中返回所有雇员的名字和姓氏,并从部门表中返回他们的部门名称,但仅返回那些超过平均水平的雇员他们部门的薪水?
谢谢你的回答
最佳答案
该查询应为您提供所需的信息。
select firstName, lastName, departmentName
from Employees e join
(select departmentID, departmentName, AVG(salary) AS averageSalary
from Department d
join Employees e ON e.departmentID=d.departmentID
group by departmentId, departmentName) ds
on ds.departmentID=e.departmentID
where e.salary>ds.AverageSalary
(PS:我同意上面的评论。张贴到目前为止的尝试是一种礼节。这次您很幸运!:-)
关于sql - T-SQL子查询和可能的联接的正确语法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3126627/