MySQL高级 第10章子查询优化

1. 案例

取所有不为掌门人的员工,按年龄分组!

②进一步优化,替换not in。

上述SQL可以替换为:

 select age as '年龄',count(*) as '人数' from emp e left join dept d on e.id=d.ceo where d.id is null group by age;