题解 | 汇总各个部门当前员工的title类型的分配数目
select d.dept_no,d.dept_name,t.title,count(t.title) as count from titles t left join ( select d1.emp_no as emp_no,d1.dept_no as dept_no,d2.dept_name as dept_name from dept_emp d1 left join departments d2 on d1.dept_no = d2.dept_no where d1.to_date = "9999-01-01") d on t.emp_no = d.emp_no where t.to_date = "9999-01-01" group by d.dept_no,t.title order by d.dept_no;