select * from (
select deptno, count(ename) as shuli, avg(sal) as 平均工资 from emp as tA where sal > (select avg(sal) from emp where deptno = tA.deptno) group by deptno
) as t where shuli > 1
select deptno, sum(case when e1.sal>avg(e2.sal) then 1 else 0) as peoplecount, avg(e2.sal)
from emp e1 join emp e2
on e1.deptno=e2.deptno
having sum(case when e1.sal>avg(e2.sal) then 1 else 0)>=1
group by e1.deptno,e2.deptno
order by e2.deptno