试题连接
select titles.title,AVG(salaries.salary) from titles inner join salaries on titles.emp_no = salaries.emp_no group by titles.title order by AVG(salaries.salary) asc
分析:
已知有三表:
三表连接
select t1.last_name,t1.first_name,t3.dept_name from employees as t1 left outer join dept_emp as t2 on t1.emp_no = t2.emp_no left join departments as t3 on t2.dept_no = t3.dept_no
三表查询
分组,计算每个部门的记录行数 count(1)
select t1.dept_no,t1.dept_name,count(1) from departments as t1 left outer join dept_emp as t2 on t1.dept_no = t2.dept_no left outer join salaries t3 on t2.emp_no = t3.emp_no group by t1.dept_no order by t1.dept_no asc