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

后端 未结 7 1410
臣服心动
臣服心动 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:35

    Try This... This not tested.

    SELECT * from employee join (SELECT AVG(employee_salary) as sal, department_ID 
    FROM employee GROUP BY Department_ID) as t1 
    ON employee.department_ID = t1.department_ID 
    where employee.employee_salary > t1.sal
    

提交回复
热议问题