zoukankan      html  css  js  c++  java
  • oracle子查询


    子查询:在一个查询的内部包含另外一个查询。


    普通子查询


    -- 查询出比7654工资还高的所有雇员的信息
    select * from emp e where e.sal > (select sal from emp where empno = 7654);
    
    -- 查询出工资比7654高,同一时候与7788从事同样工作的所有雇员的信息
    select * from emp e
    where e.sal > (select sal from emp where empno = 7654)
    and e.job = (select job from emp where empno = 7788);
    
    -- 查询出工资最低的雇员姓名、工作、工资
    select e.ename, e.job, e.sal from emp e
    where e.sal = (select min(sal) from emp);


    in 查询


    in keyword用来匹配一个集合中的记录

    -- 查询雇员编号为1234,2345,7369,7900的雇员信息
    select * from emp where empno in(1234, 2345, 7369, 7900);



    -- 查询雇员编号不是 1234,2345。7369,7900的雇员信息
    select * from emp where empno not in(1234, 2345, 7369, 7900);


    -- 查询每一个部门的最低工资相应的员工信息
    select * from emp where sal in (select min(sal) from emp group by deptno);



    anykeyword


    any:表示随意的。

    < any 比子查询返回的随意一个结果小就可以,即小于返回结果的最大值

    = any 和子查询中随意一个结果相等就可以。相当于in

    > any 比子查询返回的随意一个结果大就可以,即大于返回结果的最小值


    -- 查询每一个部门的最低工资
    select min(sal) min_sal from emp group by deptno;


    sal 大于 any (每一个部门最低工资),即大于返回结果的最小值

    select * from emp where sal > any (select min(sal) from emp group by deptno);



    sal = any (每一个部门最低工资),即 和子查询中每一个结果相等,同in

    select * from emp where sal = any (select min(sal) from emp group by deptno);


    sal < any (每一个部门最低工资)。即大于返回结果的最大值

    select * from emp where sal < any (select min(sal) from emp group by deptno);



    allkeyword


    all:表示全部的。

    < all 比子查询返回的全部的结果都小,即小于返回结果的最小值

    > all 比子查询返回的全部的结果都大,即大于返回结果的最大值

    = all 无意义。逻辑上也不成立


    查询工资在2000 到 3500的工资段的工资集合

    select distinct sal from emp where sal between 2000 and 3500;


    > all (工资在2000 到 3500的工资段的工资集合) ,即大于最大值

    select * from emp where sal > all(select distinct sal from emp where sal between 2000 and 3500);



    < all (工资在2000 到 3500的工资段的工资集合),即小于最小值

    select * from emp where sal < all(select distinct sal from emp where sal between 2000 and 3500);




  • 相关阅读:
    postman批量运行和参数化
    Loadrunner 参数化数据分配方法以及数据更新方式
    常用函数
    获取 layer.msg 弹窗的信息
    登录页脚本小结
    关于linux下system()函数的总结
    请不要重复犯我在学习Python和Linux系统上的错误
    教你摸清 Linux PC 的性能底细?
    Ubuntu GNOME 16.10 Beta 1问世了!
    Google疯了,竟然这样!
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5219498.html
Copyright © 2011-2022 走看看