加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle 子查询

发布时间:2020-12-12 13:16:43 所属栏目:百科 来源:网络整理
导读:多行子查询 单行子查询只返回一行结果 多行子查询返回多行结果 多行子查询结果操作符(in,any,all) any 与任意值比较 all 与所有值比较 in 属于集合 in in集合中有空值,忽略空值,返回不为空的行; not in 集合中有空值,返回空 any all all 小于最大 all

多行子查询

  • 单行子查询只返回一行结果
  • 多行子查询返回多行结果
  • 多行子查询结果操作符(in,any,all)
  • any 与任意值比较
  • all 与所有值比较
  • in 属于集合

in

  • in集合中有空值,忽略空值,返回不为空的行;
  • not in 集合中有空值,返回空

any all

  • <all 小于最大
  • >all 大于最小
  • =any 相当于 in
  • >all 大于最大
  • <all 小于最小
  • != all 相当于 not in

多列子查询

select empno,ename,sal,job from emp
    where (job,sal) = (select job,sal from emp where empno=7788)
        and empno <> 7788;
        
select empno,sal) in (select job,sal from emp where empno=7788)
        and empno <> 7788;

相关子查询

外层值参与内层查询的运算,执行顺序为 外层取值 - 传到内层进行运算 - 内层运算返回值参与外层运算 (循环交错查询)

select e.ename,e.sal,e.deptno
from emp e where e.sal > (select avg(s.sal) from emp s
                                        where e.deptno = s.deptno);

非相关子查询

内层查询与外层查询无关,子查询只执行一次,返回结果后参与外层运算

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读