1.
一个部门的平均工资:
select avg(工资) from table_name where 部门=10;
select avg(工资) from table_name where 部门=20;
平均工资差距:
select (select avg(工资) from table_name where 部门=10) -
(select avg(工资) from table_name where 部门=20) as xx
from dual;
2.
如果你的dept表中有对应员工信息的话:
select 部门名称,部门id
from dept
group by 部门名称,部门id
having count(1)>0;
如果是两个表,一个部门表dept,一个部门和员工对应关系表table2
这是有员工的部门:
select distinct a.部门名称,a.部门id
from dept a, table2 b
where a.部门id = b.部门id;
没员工的部门:
select 部门名称,部门id
from dept a
where not exists (
select 'x' from table2 b
where a.部门id = b.部门id);
或者:
select 部门名称,部门id
from dept a
where 部门id not in
(select 部门id from table2);
温馨提示:答案为网友推荐,仅供参考