SELECT every employee that has a higher salary than the AVERAGE of his department

后端 未结 7 1349
臣服心动
臣服心动 2021-01-13 23:46

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

Employee_Name, Employee_Salary, Department_ID
7条回答
  •  感情败类
    2021-01-14 00:31

    please try with below query

    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)
    

    or

    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)
    

提交回复
热议问题