题解 | 统计各个部门的工资记录数
解题思路:
将下面俩表左连接查出要的数据,在和第一个表左连接查出最终数据
select d1.dept_no as dept_no, d1.dept_name as dept_name, d2.sum as sum from departments d1 left join ( select d.dept_no as dept_no,count(s.salary) as sum from dept_emp d left join salaries s on d.emp_no = s.emp_no group by d.dept_no) d2 on d1.dept_no = d2.dept_no group by d1.dept_no;