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

    select * from teacher

    --招生部门所有男老师姓名
    --teacher表中有 招生部吗 ? 有的是编号!
    --01.查询 招生部对应的编号
    select dname,deptno from dept where dname='招生部'
    --02.那么只要是部门编号是20的 就是招生部
    select tname,deptno
    from teacher
    where deptno=(select deptno from dept where dname='招生部')

    --所有老师姓名、部门
    --怎么把deptno转换成dname
    select tname,deptno from teacher
    select dname from dept
    --把deptno换成上面的语句
    --子查询作为了 列名
    select tname,(select dname from dept where deptno=t.deptno) as 部门
    from teacher t

    --所有在招生部、人力部的老师列表
    select deptno,tname from
    teacher
    where deptno in
    (select deptno from dept where dname in('招生部','人力部'))


    --使用exists 用来检查子查询是否返回一个数据 性能比in高
    --使用exists 代替in 使用not exists代替 not in
    --exists并不返回实际的数据 而是返回 true或者false
    select deptno,tname from
    teacher where exists
    (select deptno from dept
    where
    deptno=teacher.deptno and dname in('招生部','人力部'))

      (以上内容来自王硕老师)

  • 相关阅读:
    webpack 3.X学习之Babel配置
    git常用命令记录
    let const
    数据存储之HTTP Cookie
    cookie sessionStorage localStorage 之间的关系
    数据存储之Web存储(sessionStorage localStorage globalStorage )
    express官网学习笔记
    最近计划
    node.js进阶话题
    node.js核心模块
  • 原文地址:https://www.cnblogs.com/liu-chao-feng/p/5890331.html
Copyright © 2011-2022 走看看