题解 | #统计各个部门的工资记录数#
统计各个部门的工资记录数
http://www.nowcoder.com/practice/6a62b6c0a7324350a6d9959fa7c21db3
SELECT
d.dept_no
,d.dept_name
,COUNT(s.salary) sum
FROM departments d
join dept_emp de
on d.dept_no=de.dept_no
join salaries s
on de.emp_no=s.emp_no
group by d.dept_no
d.dept_no
,d.dept_name
,COUNT(s.salary) sum
FROM departments d
join dept_emp de
on d.dept_no=de.dept_no
join salaries s
on de.emp_no=s.emp_no
group by d.dept_no
order by d.dept_no
虽然order by 可以不加,但是不加最后不能算正确答案。