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部分效率低下,不推荐使用。
随笔有些是自己写的,有些是根据网上的东西自己整理的,文章基本都是别人的,只是为方便查看复制到那里

浙公网安备 33010602011771号