zoukankan      html  css  js  c++  java
  • Oracle--子查询

    1、子查询
        是指嵌入在其他sql语句中的select语句,也叫嵌套语句
    2、单行子查询
        单行子查询是指只返回一行数据的子查询语句
        Q:如何显示与SMITH同一部门的所有员工
            select * from emp where deptno=(select deptno from emp where
            ename='SMITH');
    3、多行子查询
        多行子查询是指返回多行数据的子查询
        Q:如何查询和部门10的工作相同的雇员的名字、岗位、
            工资、部门号
            select * from emp where job in(select distinct job from emp where
            deptno=10);
    4、多行子查询中使用all操作符
        Q:如何显示工资比部门30的所有员工的工资高的员工的姓名、工资、
            部门号。
               ① select ename,sal,deptno from emp where 
                sal>all(select sal from emp where deptno=30 );
                ②select ename,sal,deptno from emp where 
                sal>(select max(sal) from emp where deptno=30);
    5、在多行子查询中使用any操作符
        Q:如何显示工资比部门30的任意一个员工的工资高的员工的姓名、工资和部门号
                ①select ename,sal,deptno from emp where sal>any
                (select sal from emp where deptno=30);
                ②select ename,sal,deptno from emp where 
                sal>(select min(sal) from emp where deptno=30);
     
        Q:如何显示与SMITH部门和岗位完全相同的所有员工
            select * from emp where (deptno,job)=(select deptno,job from emp 
             where ename='SMITH');
     
    6、在from子句中使用子查询
        Q:如何显示高于自己部门平均工资的员工的信息
            1、select deptno,avg(sal) myAvgSal from emp group by deptno;
            2、select  a1.ename,a1.deptno,a1.sal,a2.deptno,a2.myAvgSal from emp a1,(select deptno,avg(sal) myAvgSal from emp group by deptno) a2 where  a1.deptno=a2.deptno and a1.sal>a2.myAvgSal; 
  • 相关阅读:
    紫色飞猪的研发之旅--07client-go实现进入pod模拟终端登录
    紫色飞猪的研发之旅--06go自定义状态码
    紫色飞猪的研发之旅--05go封装http请求
    紫色飞猪的研发之旅--04client-go客户端
    紫色飞猪的研发之旅--03golang:获取cookie
    支持remote write和exemplar的prometheus服务
    从头编写一个时序数据库
    解析Prometheus PromQL
    老板:把系统从单体架构升级到集群架构!
    小白自制Linux开发板 三. Linux内核与文件系统移植
  • 原文地址:https://www.cnblogs.com/ZKeJun/p/8940064.html
Copyright © 2011-2022 走看看