我有两个表,其中包含有关员工和部门的信息。两者看起来如下
员工表:
ID_emp ID_dep year
3000 4 0
3001 4 1
3002 4 2
3003 16 3
3004 15 3
部门表:
ID_dep dep_descr
16 management
4 accounting
现在,我需要找出每个部门受雇超过1年的员工人数,并提供每个部门的员工人数相对于整个公司受雇超过1年的员工总数的百分比(所有部门)。
结果应如下所示:
dep_descr number of employees percent of total employees
management 12 5%
accounting 4 1.6%
... ... ...
那这个呢?
select
concat(cast(count(e.id_emp)/(select count(id_emp) from employee) * 100 as decimal(4,2)), '%') employees_in_dept, d.dep_descr
from employee e
inner join department d
on e.id_dep = d.id_dep
group by d.id_dep
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句