栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Mysql数据库的交、差运算

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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;

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    |
+-----------+
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/878265.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号