先上正确代码
select d.dept_no,
d.dept_name,
t.title,
count(t.title)as count
from departments d,dept_emp de,titles t
where de.emp_no=t.emp_no
and de.dept_no=d.dept_no
and de.to_date='9999-01-01'
and t.to_date='9999-01-01'
group by d.dept_no,t.title下面是我一开始写的,很典型的易错点
select d.dept_no,
d.dept_name,
t.title,
count(t.title)as count
from departments d,dept_emp de,titles t
where de.emp_no=t.emp_no
and de.dept_no=d.dept_no
and de.to_date='9999-01-01'
and t.to_date='9999-01-01'
group by d.dept_no -- 只按照部门分组,不符合题意的;同理只按title分组也不行
京公网安备 11010502036488号