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);




  • 相关阅读:
    git回退版本,已经commit过的文件丢了
    null is not an object (evaluating 'Picker._init')
    Mac电脑 怎么导出安卓手机的相册
    iOS----------适配iOS12
    iOS----------Xcode 无线调试
    iOS---------获取当前年份
    2018-08-10
    【2020Python修炼记】前端开发之 jQuery 动画、插件机制
    【2020Python修炼记】前端开发之 jQuery 属性/样式操作&绑定事件
    【2020Python修炼记】前端开发之 jQuery实战— jQuery简易版网页
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/5219498.html
Copyright © 2011-2022 走看看