我正在尝试计算所有空缺职位,“职位”表包含所有可用职位,“员工”表包含该职位的所有员工。当我运行下面的语句时,我收到
Department Job Code Count(*)
10 2 1
10 1 1
但我期待这个;因为目前职位代码“3”中没有员工
Department Job Code Count(*)
10 3 0
10 2 1
10 1 1
如何让 Job Code 3 的计数显示为“0”或“null”也是可以接受的
select pos.department, pos.job_code, count(*)
from paposition pos
left join employee emp
on (pos.department = emp.department
and pos.job_code = emp.job_code)
where pos.job_code in ('1', '2', '3')
and pos.end_date = '01-Jan-1700'
and (emp.emp_status like 'A%'
or emp.emp_status like 'L%')
and emp.department = '0010'
group by pos.department, pos.job_code
order by pos.department, pos.job_code