• Oracle【三表的联合查询】


     1 insert into city values(1,'北京','彰显大气');
     2 insert into city values(2,'上海','繁华都市');
     3 insert into city values(3,'广州','凸显舒适');
     4 insert into city values(4,'深圳','年轻气氛');
     5 insert into city values(5,'北上广深','不相信眼泪');
     6 commit;
     7 update dept set loc='1' where deptno=70;
     8 update dept set loc='2' where deptno=10;
     9 update dept set loc='3' where deptno=20;
    10 update dept set loc='4' where deptno=30;
    11 update dept set loc='5' where deptno=40;

    员工信息表:select * from emp;

    员工部门表:select * from dept;

    城市表:select * from city;

    三表联合查询举栗子:查询员工信息及部门名称及所在城市的名称

     1 --SQL92:查询员工信息及部门名称及所在城市的名称并且工资大于2000或者有奖金的
     2 select e.*,d.dname,c.cname
     3 from emp e,dept d,city c
     4 where (e.deptno=d.deptno and d.loc=c.cid and e.sal>2000)or(e.deptno=d.deptno and d.loc=c.cid and comm is not null)
     5 order by e.sal;
     6 --SQL99:查询员工信息及部门名称及所在城市的名称并且工资大于2000或者有奖金的
     7 select e.*,d.dname,c.cname
     8 from emp e
     9 inner join dept d
    10 on e.deptno=d.deptno
    11 inner join city c
    12 on d.loc=c.cid
    13 where e.sal>2000 or e.comm is not null
    14 order by e.sal;

    重点重点重点!!!

    --SQL92:
      --特点:易于书写,难于阅读
      --缺点:92SQL语句结构不清晰。
      --用法:
        --select 内容(别名,连接符,Oracle函数等)
        --from 表名1,表名2,表名3...
        --where 条件(连接条件,普通筛选条件,where子句关键字)
        --group by 分组字段
        --having 多行函数筛选
        --order by 排序字段
    
    --SQL99
    --特点:难于书写,易于阅读。
    --用法:
        --select 内容 
        --from 表名1
        --inner join 表名2
        --on 连接条件
        --inner join 表名3
        --on 连接条件
        --where 条件(连接条件,普通筛选条件,where子句关键字)
        --group by 分组字段
        --having 多行函数筛选
        --order by 排序字段
  • 相关阅读:
    函数指针实例二
    函数指针实例一
    【计算机系统】指令流水线
    函数指针实例
    好书记录
    GPIO程序在PC上的模拟学习
    gcc——预处理(预编译),编译,汇编,链接
    gdb调试时查看内存
    结构体指针变量的定义
    VC++ 定制应用程序的外观
  • 原文地址:https://www.cnblogs.com/cao-yin/p/9747522.html
Copyright © 2020-2023  润新知