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; 
  • 相关阅读:
    【WPF】 Prism 框架中,TabControl 作为Region时如何设置Header
    【WPF】将控件事件中的参数,传递到ViewModel中
    WPF 一种带有多个子集的类ComBox 解决方法
    WPF TabControl美化
    【WPF】 问题总结-RaidButton修改样式模板后作用区域的变化
    C# 打开Excel文件
    获取文件夹下所有的文件名
    访问需要HTTP Basic Authentication认证的资源的c#的实现 将账号密码放入url
    第十三章 建造者模式(Builder)
    第十二章 外观模式 (Facade)
  • 原文地址:https://www.cnblogs.com/ZKeJun/p/8940064.html
Copyright © 2011-2022 走看看