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;
上一篇: MySQL高级 第9章关联查询优化
下一篇: MySQL高级 第11章排序分组优化
取所有不为掌门人的员工,按年龄分组!
②进一步优化,替换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;