SELECT使用子查询

SELECT使用子查询
  SELECT使用子查询,该子查询会执行多次,
 次数是由记录数量决定。效率比较低,不推荐使用。
 //查询部门编号,工资大于等于2000的人数,
 //工资小于2000的人数
 select distinct deptno,
   (select count(*)
    from emp
    where sal>=2000 and deptno=e.deptno) great,
   (select count(*)
    from emp
    where sal<2000 and deptno=e.deptno) less
 from emp e
 where deptno is not null;
 
 提示:重点关注子查询在FROM,WHERE,HAVING部分的使用。
 SELECT部分效率低下,不推荐使用。
原文地址:https://www.cnblogs.com/yunman/p/5497544.html