选择每个薪水高于其部门平均水平的员工 [英] SELECT every employee that has a higher salary than the AVERAGE of his department

查看:75
本文介绍了选择每个薪水高于其部门平均水平的员工的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中只有1个名为 EMPLOYEE 的表,下面是3个列:

I have only 1 table named EMPLOYEE on my database with the 3 following collumns:

Employee_Name, Employee_Salary, Department_ID

现在,我必须选择每位薪水高于其部门平均水平的员工. 我该怎么做?

Now I have to SELECT every employee that has a higher salary than the AVERAGE of his department. How do I do that?

我遇到的主要问题是,将每个Employee_Salary与

The main problem that I have is that when comparing each Employee_Salary with

SELECT  AVG(department_ID) FROM employee GROUP BY Department_ID

内部队列的返回集返回多行.

the return set of the inner queue returns multiple rows.

我认为我需要执行加入操作,但是我不知道如何做.

I think I need to perform a join operation but I do not know how.

推荐答案

请尝试以下查询

Select * from employee a where Employee_Salary > (select avg(Employee_Salary) from 
employee b group by Department_ID having b.Department_ID = a.Department_ID)

Select * from employee a where Employee_Salary> (select avg(Employee_Salary) from 
employee b where b.Department_ID = a.Department_ID group by Department_ID)

这篇关于选择每个薪水高于其部门平均水平的员工的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆