题解 | 统计各个部门的工资记录数
with tmp as ( select t.*,s.salary from ( select t2.emp_no,t2.dept_no,t1.dept_name from departments as t1 inner join dept_emp as t2 on t1.dept_no = t2.dept_no) as t inner join salaries as s on t.emp_no = s.emp_no) select dept_no,dept_name,count(*) as sum from tmp group by dept_no,dept_name order by dept_no asc;