0

我需要检索收入高于其部门平均工资的员工的信息……我们有名为 10、20、30、40、50……的部门,以此类推。在这里,我设法检索到我只需要一个部门的东西。(40) 我怎样才能为尽可能多的部门做到这一点?

这是我的查询:

SELECT  * FROM    EMPLOYEE where (Department_ID='40')and 
 (
 employee_salary > 
  (select avg(employee_salary) from EMPLOYEE  where  Department_ID='40')   
 )

Datatable数据表

4

4 回答 4

4

希望这会做,

    SELECT  emp.* FROM    EMPLOYEE emp where emp.employee_salary >
      (  select avg(employee_salary) from EMPLOYEE new1 
         where emp.Department_ID=new1.Department_ID 
         group by  Department_ID  
      ) 
于 2012-12-19T11:22:43.897 回答
0

试试这个查询

select * from EMPLOYEE as e1
where e1.employee_salary > (select avg(employee_salary) 
                         from EMPLOYEE as e2 
                         where e1.department_id=e2.department_id
                         group by Department_id)
于 2012-12-19T11:21:18.833 回答
0

你可以试试这个:

    SELECT  *, avg(employee_salary) as average_salary 
FROM    EMPLOYEE 
where Department_ID='40' 
having average_salary<employee_salary
于 2012-12-19T11:23:04.017 回答
0
select e.* from employee as e inner join
    (select department_id, avg(employee_salary) as avg_salary
        from employee group by department_id) as f
on e.department_id = f.department_id
where e.employee_salary > f.avg_salary;
于 2012-12-19T11:24:21.127 回答