子查询的正确语法和连接(如果有)是什么,它将从员工表中返回所有员工的名字和姓氏,并从部门表中返回他们的部门名称,但只返回那些更多的员工比他们部门的平均工资? 谢谢你的回答
答案 0 :(得分:9)
此查询应该可以为您提供所需内容。
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:我同意上面的评论。发布你迄今为止尝试的内容是礼仪。这次你很幸运!: - )