题解 | #汇总各个部门当前员工的title类型的分配数目#
汇总各个部门当前员工的title类型的分配数目
http://www.nowcoder.com/practice/4bcb6a7d3e39423291d2f7bdbbff87f8
用where将departments,dept_emp,titles连接起来,然后用group by根据dept_no,title分组,这时count就可以根据第二层group来计算每个title的数量,最后再根据dept_no,title排序
select d.dept_no, d.dept_name, t.title, count(t.title)
from departments as d, dept_emp as de, titles as t
where d.dept_no = de.dept_no and de.emp_no = t.emp_no
group by d.dept_no, t.title
order by d.dept_no, t.title