题解 | #汇总各个部门当前员工的title类型的分配数目#
汇总各个部门当前员工的title类型的分配数目
http://www.nowcoder.com/practice/4bcb6a7d3e39423291d2f7bdbbff87f8
SELECT
d.dept_no,
d.dept_name,
t.title,
count( t.emp_no )
FROM
departments AS d
LEFT JOIN dept_emp AS de ON d.dept_no = de.dept_no
LEFT JOIN titles AS t ON de.emp_no = t.emp_no
WHERE
de.to_date = '9999-01-01'
AND t.to_date = '9999-01-01'
GROUP BY
d.dept_no,
d.dept_name,
t.title
ORDER BY
d.dept_no