问题:查询员工工资高于其所在部门平均工资的员工的信息
1.使用嵌套子查询的方法。
select * from Employee e1
where e1.salary>
(select AVG(salary) from Employee e2
where e1.depId=e2.depId
group by e2.depId
)
2.在from子句中使用子查询。在from子句中使用子查询时,必须给子查询指定别名。
select e1.* from
Employee e1,(select depId,avg(salary) avgsalary from Employee group by depName) e2
where e1.depId=e2.depId and e1.salary>e2.avgsalary