SQL92&SQL99实现三表联合查询

–SQL92&SQL99实现三表联合查询
–创建city表:使用图形操作即可
–给city表添加测试数据

List item

insert into city values(1,'商丘','历史闻名古都');
insert into city values(2,'邯郸','历史闻名古都');
insert into city values(3,'洛阳','历史闻名古都');
insert into city values(4,'开封','历史闻名古都');

–将部门表中的loc字段设置为城市表的城市编号
update dept set loc=‘1’ where deptno=50;
update dept set loc=‘2’ where deptno=40;
update dept set loc=‘3’ where deptno=30;
update dept set loc=‘4’ where deptno=20;
update dept set loc=‘4’ where deptno=10;
–完成三表联合查询
–SQL92实现:查询员工信息及部门名称及所在城市名称并且员工的工资大于2000或者有奖金
–特点:易于书写,难于阅读
–缺点:92的SQL语句结构不清晰
–用法:
–select 内容 (别名,连接符,去除重复,oracle函数,逻辑运算)
–from 表名1,表名2,表名3…
–where 条件(连接条件,普通筛选条件,where子句关键字)
–group by 分组字段
–having 多行函数筛选
–order by 排序字段
select e.*,d.dname,c.cname
from emp e,dept d,city c
where (e.deptno=d.deptno and d.loc=c.cid and sal>2000) or (e.deptno=d.deptno and d.loc=c.cid and comm is not null)
order by e.sal
–SQL99实现:查询员工信息及部门名称及所在城市名称并且员工的工资大于2000或者有奖金
–特点:难于书写,易于阅读
–使用:
–select 内容 from 表名1
– inner join 表名2
– on 连接条件
–inner join 表名3
–on 连接条件
–where 普通筛选条件
–group by 分组
–having 多行函数筛选
–order by 排序
select * from emp e
inner join dept d
on e.deptno = d.deptno
inner join city c
on d.loc =c.cid
where e.sal>2000 or e.comm is not null
order by e.sal

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值