列出各个部门中工资高于本部门的平均工资的员工数和部门号,并按部门号排序

SQL数据库浏览:278收藏:1
答案:
employee: eid, ename, salary, dept_id

select count(*), a.dept_id
from employee a
where
a.salary > (select avg(b.salary) from employee b where b.dept_id = '本部门')
group by a.dept_id
order by a.dept_id