先从【部门员工关系表/工资表】筛选出【部门ID】【工资记录数】
再关联出【部门名称】
使用到:
1.聚合函数,group by
2.左连接,left join
3.行数,count()
select a.dept_no,a.dept_name,r.sum from departments a left join ( select w.dept_no,count(w.dept_no) as sum from dept_emp w left join salaries e on w.emp_no = e.emp_no group by w.dept_no ) r on a.dept_no = r.dept_no