记下SQL以显示员工(工资大于5000)的平均工资小于8000的部门

时间:2017-03-20 17:24:35

标签: sql

记下SQL,以显示员工(工资大于5000)的平均工资低于8000的部门。

这就是我写的。我不确定这是否正确。

select departments.department_name, employees.avg(salary) as avgsalary from departments
inner join employees
on departments.department_id = employees.department_id
where avgsalary > 5000 and avgsalary < 8000;

1 个答案:

答案 0 :(得分:1)

select departments.department_name
    , avg(employees.salary) as avgsalary 
from departments inner join employees
    on departments.department_id = employees.department_id
group by departments.department_name
having avg(employees.salary) > 5000 and avg(employees.salary) < 8000;