Mysql数据库的交、差运算

Mysql数据库的交、差运算

1、操作表section

在这里插入图片描述

2、创建中间表

1、创建fall表

create table fall select * from section where semester = 'Fall' and year = 2017;

在这里插入图片描述

2、创建spring表

create table spring select * from section where semester = 'Spring' and year = 2018;

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-U0j6XOAK-1652253110478)(C:\Users\惊蛰\AppData\Roaming\Typora\typora-user-images\image-20220511143726445.png)]

3、进行交差运算

1、进行交运算

select course_id from spring inner join fall using(course_id);
//查找既在2017年秋季又在2018年春季开设的课程
select course_id from fall where course_id in(select course_id from spring);
+-----------+
| course_id |
+-----------+
| CS-101    |
+-----------+

+-----------+
| course_id |
+-----------+
| CS-101    |
+-----------+

2、进行差运算

select course_id from spring left join fall using(course_id) where fall.course_id is null;
//查询在2018年春季开设单不在2017年秋季开设的课程;
select course_id from spring where course_id not in(select course_id from fall);
+-----------+
| course_id |
+-----------+
| CS-315    |
| CS-319    |
| CS-319    |
| FIN-201   |
| HIS-351   |
| MU-199    |
+-----------+
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值