From 98db851bbb0bfed389a2b5bb73492df2cf4c2d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=AB=E9=9B=AA=E8=8E=B2=E7=9A=84=E4=BD=9C=E4=B8=9A?= <1653483984@qq.com> Date: Tue, 28 Feb 2023 22:13:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E9=97=AB=E9=9B=AA=E8=8E=B2=E7=9A=84?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...63\350\201\224\346\237\245\350\257\242.md" | 227 ++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 "37 \351\227\253\351\233\252\350\216\262/20230227 \345\205\263\350\201\224\346\237\245\350\257\242.md" diff --git "a/37 \351\227\253\351\233\252\350\216\262/20230227 \345\205\263\350\201\224\346\237\245\350\257\242.md" "b/37 \351\227\253\351\233\252\350\216\262/20230227 \345\205\263\350\201\224\346\237\245\350\257\242.md" new file mode 100644 index 0000000..223ece2 --- /dev/null +++ "b/37 \351\227\253\351\233\252\350\216\262/20230227 \345\205\263\350\201\224\346\237\245\350\257\242.md" @@ -0,0 +1,227 @@ +# 1.笔记 + +## 关联查询 + +```sql +1,内连接:inner join ... on + +2、左连接:A left join B on + +(2)A表全部 + +(3)A表- A∩B + +3、右连接:A right join B on + +4、全外连接:full outer join ... on,但是mysql不支持这个关键字,mysql使用union(合并)结果的方式代替 + +(6)A表∪B表: (2) A表结果 union (4)B表的结果 + +(7)A∪B - A∩B (3)A表- A∩B结果 union (5)B表-A∩B结果 +``` + +# 2.作业 + +```sql +create database zuoye2 charset utf8; +use zuoye2; + +create table student( + sno varchar(20)primary key, + sname varchar(20)not null, + ssex varchar(20)not null, + sbirthday datetime, + class varchar(20) +); +``` + +```sql +create table course( + cno varchar(20)primary key, + cname varchar(20) not null, + tno varchar(20)not null, + foreign key (tno) references teacher(tno) +); +``` + +```sql +create table score( + sno varchar(20)not null, + cno varchar(20)not null, + degree decimal(4,1), + foreign key (sno) references student(sno), + foreign key (cno) references course(cno) +); +``` + +```sql +create table teacher( + tno varchar(20)primary key, + tname varchar(20)not null, + tsex varchar(20)not null, + tbirthday datetime, + prof varchar(20), + depart varchar(20)not null +); +``` + +```sql +insert into student values(108,'曾华','男','1977-9-1','95033'); +insert into student values(105,'匡明','男','1975-10-2','95031'); +insert into student values(107,'王丽','女','1976-1-23','95033'); +insert into student values(101,'李军','男','1976-2-20','95033'); +insert into student values(109,'王芳','女','1975-2-10','95031'); +insert into student values(103,'陆君','男','1974-6-3','95031'); + +insert into course values('3-105','计算机导论','825'); +insert into course values('3-245','操作系统','804'); +insert into course values('6-166','数字电路','856'); +insert into course values('9-888','高等数学','831'); + +insert into score values('103','3-245','86'); +insert into score values('105','3-245','75'); +insert into score values('109','3-245','68'); +insert into score values('103','3-105','92'); +insert into score values('105','3-105','88'); +insert into score values('109','3-105','76'); +insert into score values('101','3-105','64'); +insert into score values('107','3-105','91'); +insert into score values('108','3-105','78'); +insert into score values('101','6-166','85'); +insert into score values('107','6-166','79'); +insert into score values('108','6-166','81'); + +insert into teacher values('804','李诚','男','1958-12-2','副教授','计算机系'); +insert into teacher values('856','张旭','男','1969-3-12','讲师','电子工程系'); +insert into teacher values('825','王萍','女','1972-5-5','助教','计算机系'); +insert into teacher values('831','刘冰','女','1977-8-14','助教','电子工程系'); +``` + +- + +```sql +- 1,查询所有学生,都学了哪些课程,要显示学生信息和课程信息/ +select student.sno,sname,ssex,sbirthday,class,cname +from student left join score on student.sno=score.sno +left join course on score.cno=course.cno; +-- 2,查询没有学生的教师的所有信息\ +select tname from +teacher left join course on teacher.tno=course.tno +left join score on course.cno=score.cno +left join student on score.sno=student.sno +where min(lishi( +select count(score.cno),cname as rshu from +score right join course on score.cno=course.cno group by course.cno)); +-- 不会做别抄 + +select * from teacher; +select * from score; + +select * from course; +-- + +-- 4.查询 +-- ① 查询Score表中的最高分的学生学号和课程号。 +select sno,cno from score where degree=(select max(degree) from score); +-- ② 查询所有学生的Sname、Cno和Degree列。 +select sname,score.cno,degree from student inner join score on student.sno=score.sno; +-- ③ 查询所有学生的Sno、Cname和Degree列。 +select score.sno,cname,degree from score inner join course on score.cno=course.cno; +-- ④ 查询所有学生的Sname、Cname和Degree列。 +select sname,cname,degree from student inner join score on student.sno=score.sno inner join course on score.cno=course.cno; +-- ⑤ 查询“95033”班学生的平均分。 +select avg(score.Degree) from score inner join student on student.Sno = score.Sno where student.Class = '95033'; +-- ⑥ 查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。 +select * from student +inner join score on student.sno=score.sno +where score.cno='3-105' and degree > +(select degree from score where score.sno=109 and score.cno='3-105' ); +-- ⑦ 查询score中选学多门课程的同学中分数为非最高分成绩的记录。 +select max(score.degree) from score where 1< (select count(sno) from score) +select count(sno) from score group by sno +-- 不会做别抄 +-- ⑧ 查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。 +select * from score +where degree>( +select degree from score where score.sno=109 and score.cno='3-105'); +-- ⑨ 查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。 +select sno,sname,sbirthday from +student where sbirthday=(select sbirthday from student where sno=108); +-- 这个只有他自己生日一样下面是不输出他自己生日的代码 +select sno,sname,sbirthday from student +where sbirthday=(select sbirthday from student where sno=108) +and sno!=108; +-- ⑩ 查询“张旭“教师任课的学生成绩。 +select degree from score left join course +on score.cno=course.cno +left join teacher +on course.tno=teacher.tno +where score.cno=( +select course.cno from course left join teacher +on course.tno=teacher.tno +where tname='张旭') +-- ⑪ 查询选修某课程的同学人数多于5人的教师姓名。 +select tname from teacher left join course +on teacher.tno=course.tno +left join score +on course.cno=score.cno +where (select count(score.cno) from score group by cno ) +-- 不会做 +-- ⑫ 查询出“计算机系“教师所教课程的成绩表。 +select score.sno,score.cno,degree from score left join course +on score.cno=course.cno +left join teacher +on course.tno=teacher.tno +where depart='计算机系'; + +-- ⑬ 查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。 +select tname,prof from teacher where prof in (select distinct prof from teacher); +-- ⑭ 查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。 + +select score.cno,score.sno,score.degree from +score inner join course +on score.cno = course.cno +and score.cno = '3-105' +and score.degree > ( +select max(degree) from score where score.cno='3-245') +order by score.degree desc; +-- ⑮ 查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degree. +select score.cno,score.sno,score.degree from +score inner join course +on score.cno = course.cno +and score.cno = '3-105' +and score.degree > ( +select max(degree) from score where score.cno='3-245'); +-- ⑯ 查询成绩比该课程平均成绩低的同学的成绩表。 +select degree +-- ⑰ 查询所有任课教师的Tname和Depart. +select tname,depart from teacher +-- 不会做 +-- ⑱ 查询所有未讲课的教师的Tname和Depart. +select tname,depart from teacher +-- 不会做 +-- ⑲ 查询“男”教师及其所上的课程。 +select tname,cname from teacher left join course +on teacher.tno=course.tno +where tsex='男'; +-- ⑳ 查询最高分同学的Sno、Cno和Degree列。 +select sno,cno,degree from score where degree=( +select max(degree) from score); +-- 21 查询和“李军”同性别的所有同学的Sname. +select sname from student +where ssex=(select ssex from student where sname='李军'); +-- 22 查询和“李军”同性别并同班的同学Sname. +select sname from student +where ssex=(select ssex from student where sname='李军') +and class=(select class from student where sname='李军'); +-- 23 查询所有选修“计算机导论”课程的“男”同学的成绩表。 +select score.* from score left join course +on score.cno=course.cno +left join student +on score.sno=student.sno +where score.cno=(select course.cno from course where cname='计算机导论') + +and ssex='男'; +-- +``` + -- Gitee From e55e1591b19ba449c93bed39224ad945b2bf8f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=AB=E9=9B=AA=E8=8E=B2=E7=9A=84=E4=BD=9C=E4=B8=9A?= <1653483984@qq.com> Date: Tue, 28 Feb 2023 22:20:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=97=AB=E9=9B=AA=E8=8E=B2=E7=9A=84?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...40\345\222\214\344\275\234\344\270\232.md" | 405 ------------------ 1 file changed, 405 deletions(-) delete mode 100644 "37 \351\227\253\351\233\252\350\216\262/20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\345\222\214\344\275\234\344\270\232.md" diff --git "a/37 \351\227\253\351\233\252\350\216\262/20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\345\222\214\344\275\234\344\270\232.md" "b/37 \351\227\253\351\233\252\350\216\262/20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\345\222\214\344\275\234\344\270\232.md" deleted file mode 100644 index 5a57fdc..0000000 --- "a/37 \351\227\253\351\233\252\350\216\262/20230220 \347\272\246\346\235\237\347\232\204\345\255\246\344\271\240\345\222\214\344\275\234\344\270\232.md" +++ /dev/null @@ -1,405 +0,0 @@ -# 一,笔记 - -```mysql -1、主键约束 - -(1)关键字是primary key - -(2)特点 - -A:每一个表只能有一个主键约束 - -B:主键约束的字段值是不允许为null - -C: 也不允许重复的 - -2、唯一键约束: - -(1)关键字:unique key - -(2)特点 - -A:允许为null - -B: 不能重复 - -B:一个表可以有多个唯一键约束 - -3,默认值约束 - -如果某个字段,在添加数据时未指定值时,希望不要用NULL处理,而是按照一个默认值处理, - -就可以使用默认值约束。 - -例如:学生性别,在未指定时,默认按照 男 处理 - -#删除score的非空约束 - ALTER TABLE student MODIFY score INT; - - #增加非空约束 - ALTER TABLE student MODIFY score INT NOT NULL; - - #删除gender的默认值约束,保留非空约束 - ALTER TABLE student MODIFY gender ENUM('男','女') NOT NULL; - -​ #删除gender的非空约束,保留默认值约束 - ALTER TABLE student MODIFY gender ENUM('男','女') DEFAULT '男'; - - #保留非空和默认值约束 - -​ ALTER TABLE student MODIFY gender ENUM('男','女') DEFAULT '男' NOT NULL; - - -外键约束 -约束两个表的关系,或者是一个表的两个字段之间的关系。 - -(1)主表(父表)和从表(子表) -主表:被依赖,被参考 -从表:依赖别人的,参考别人的 - -例如:员工表(从)和部门表(主) - - -``` - - - - - - - -# 二,作业 - -## 第1题 - -1、创建数据库test01_company - -CREATE DATABASE test01_company; -USE test01_company; - -2、创建表格offices - -| 字段名 | 数据类型 | -| ---------- | ----------- | -| officeCode | int | -| city | varchar(30) | -| address | varchar(50) | -| country | varchar(50) | -| postalCode | varchar(25) | - -CREATE TABLE offices( -officeCode int, -city varchar(30), -address varchar(50), -country varchar(50), -postalCode varchar(25) -); - - -3、创建表格employees - -| 字段名 | 数据类型 | -| ------------- | ---------------------------- | -| empNum | int(11) | -| lastName | varchar(50) | -| firstName | varchar(50) | -| mobile | varchar(25) | -| code | int | -| jobTitle | varchar(50) | -| birth | date | -| Note | varchar(255) | -| Sex | varchar(5) | - - - -CREATE TABLE employees( -empNum int(11) , -lastName varchar(50) , - firstName varchar(50) , -mobile varchar(25) , -code int , -jobTitle varchar(50) , - birth date , -Note varchar(255) , -Sex varchar(5) -); -DESC employees; - -**要求4:**将表employees的mobile字段修改到code字段后面。 -ALTER TABLE employees MODIFY mobile varchar(25) AFTER code; - -**要求5:**将表employees的birth字段改名为birthday; -ALTER TABLE employees CHANGE birth birthday date; - -**要求6:**修改sex字段,数据类型为char(1)。 -ALTER TABLE employees MODIFY sex char(1); - -**要求7:**删除字段note; -ALTER TABLE employees DROP COLUMN note; - -**要求8:**增加字段名favoriate_activity,数据类型为varchar(100); -ALTER TABLE employees ADD COLUMN favoriate_activity varchar(100); - -**要求9:**将表employees的名称修改为 employees_info -ALTER TABLE employees RENAME employees_info; - -```mysql - -``` - - - -## 第2题 - -1、创建数据库test02db -CREATE DATABASE test02db; -USE test02db; - -2、创建表格pet - -| 字段名 | 字段说明 | 数据类型 | -| ------- | -------- | ----------- | -| name | 宠物名称 | varchar(20) | -| owner | 宠物主人 | varchar(20) | -| species | 种类 | varchar(20) | -| sex | 性别 | char(1) | -| birth | 出生日期 | year | -| death | 死亡日期 | year | - -CREATE TABLE pet( -name varchar(20), -owner varchar(20), -species varchar(20), -sex char(1) , -birth year , -death year - ); - -3、添加记录 - -| name | owner | species | sex | birth | death | -| ------ | ------ | ------- | ---- | ----- | ----- | -| Fluffy | harold | Cat | f | 2003 | 2010 | -| Claws | gwen | Cat | m | 2004 | | -| Buffy | | Dog | f | 2009 | | -| Fang | benny | Dog | m | 2000 | | -| bowser | diane | Dog | m | 2003 | 2009 | -| Chirpy | | Bird | f | 2008 | | -INSERT INTO pet(name ,owner,species,sex ,birth, death) VALUES('Fluffy' , 'harold' , 'Cat ' , 'f' , 2003 , 2010 ), -('Claws' , ' gwen' , 'Cat ' , 'm' , 2004,NULL), -('Buffy ' , NULL , 'Dog ' , 'f' , 2009 ,NULL ), -('Fang' , 'benny' , 'Dog ' , 'm' , 2000,NULL ), -('bowser' , 'diane' , 'Dog ' , 'm' , 2003 , 2009 ), -('Chirpy' , NULL , ' Bird ' , 'f' , 2008,NULL ); -DESC PET; -SELECT *from pet; - - -4、 添加字段主人的生日owner_birth。 -ALTER TABLE pet ADD owner_birth varchar(50); - -5、 将名称为Claws的猫的主人改为kevin -UPDATE pet SET owner ='kevin' WHERE name ='Claws'; - -6、 将没有死的狗的主人改为duck -UPDATE pet SET owner ='duck' WHERE death is null and species='dog'; - -7、 查询没有主人的宠物的名字; -SELECT name FROM pet -WHERE owner is NULL; - - -8、 查询已经死了的cat的姓名,主人,以及去世时间; -SELECT 'name' , 'owner' ,' death' FROM pet -WHERE death IS NOT NULL and species='Cat' and species='Dog'; - -9、 删除已经死亡的狗 -DELETE FROM pet WHERE death is NOT NULL and species='Dog'; - -10、查询所有宠物信息 -SELECT * from pet; - -```sql - - -``` - -## 第3题 - -1、创建数据库:test03_company -CREATE DATABASE test03_company charset utf8; -USE test03_company; - - -```sql -create database test03_company charset utf8; -``` - -2、在此数据库下创建如下3表,数据类型,宽度,是否为空根据实际情况自己定义。 - -A. 部门表(department):部门编号(depid),部门名称(depname),部门简介(deinfo);其中部门编号为主键。 - -```mysql -use test03_company ; -create table department( - depid int primary key auto_increment, - depname char(10) not null unique key, - deinfo varchar(200) -) -```| 部门编号 | 部门名称 | 部门简介 | -| -------- | -------- | ------------ | -| 111 | 生产部 | Null | -| 222 | 销售部 | Null | -| 333 | 人事部 | 人力资源管理 | - -use test03_company ; -create table department( - depid int primary key auto_increment, - depname char(10) not null unique key, - deinfo varchar(200) -); -desc department; - - -B. 雇员表(employee):雇员编号(empid),姓名(name),性别(sex),职称(title),出生日期(birthday),所在部门编号(depid);其中 - -* 雇员编号为主键; -* 部门编号为外键,外键约束等级为(on update cascade 和on delete set null); -* 性别默认为男; - -```mysql -create table employee ( - empid int primary key auto_increment, - name varchar(10) not null, - sex enum('男','女') not null default '男', - title varchar(10), - birthday date, - depid int foreign key references department(depid) -) -``` - -C. 工资表(salary):雇员编号(empid),基本工资(basesalary),职务工资(titlesalary),扣除(deduction)。其中雇员编号为主键。 -create table salary( - empid int not null primary key auto_increment, - basesalary varchar(10)not null, - titlesalary varchar(10)not null, - deduction varchar(10), - foreign key (empid) references employee(empid) -); - - - -3、给工资表(salary)的雇员编号(empid)增加外键约束,外键约束等级为(on update cascade 和on delete cascade) - -4、添加数据如下: - -部门表: - -| 部门编号 | 部门名称 | 部门简介 | -| -------- | -------- | ------------ | -| 111 | 生产部 | Null | -| 222 | 销售部 | Null | -| 333 | 人事部 | 人力资源管理 | - - 雇员表: - -| 雇员编号 | 姓名 | 性别 | 职称 | 出生日期 | 所在部门编号 | -| -------- | ---- | ---- | ---------- | ---------- | ------------ | -| 1001 | 张三 | 男 | 高级工程师 | 1975-1-1 | 111 | -| 1002 | 李四 | 女 | 助工 | 1985-1-1 | 111 | -| 1003 | 王五 | 男 | 工程师 | 1978-11-11 | 222 | -| 1004 | 张六 | 男 | 工程师 | 1999-1-1 | 222 | - - 工资表: - -| 雇员编号 | 基本工资 | 职务工资 | 扣除 | -| -------- | -------- | -------- | ---- | -| 1001 | 2200 | 1100 | 200 | -| 1002 | 1200 | 200 | NULL | -| 1003 | 2900 | 700 | 200 | -| 1004 | 1950 | 700 | 150 | - - - -## 第4题 - -1、创建一个数据库:test04_school -create database test04_school charset utf8; -use test04_school; -2、创建如下表格 -create table Department( - DenNo int(10)primary key unique key, - DepName varchar(20)not null, - DepNote varchar(50) -); -表1 Department表的定义 - -| **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | -| ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | -| DepNo | 部门号 | int(10) | 是 | 否 | 是 | 是 | -| DepName | 部门名称 | varchar(20) | 否 | 否 | 是 | 否 | -| DepNote | 部门备注 | Varchar(50) | 否 | 否 | 否 | 否 | - -表2 Teacher表的定义 -create table teacher( - Number int unique key primary key, - Name varchar(30)not null, - Sex varchar(4), - Birth date, - DepNO int, - Salary float, - Address varchar(100), - foreign key (DepNo) references Department(DenNo) -); -| **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | -| ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | -| Number | 教工号 | int | 是 | 否 | 是 | 是 | -| Name | 姓名 | varchar(30) | 否 | 否 | 是 | 否 | -| Sex | 性别 | varchar(4) | 否 | 否 | 否 | 否 | -| Birth | 出生日期 | date | 否 | 否 | 否 | 否 | -| DepNo | 部门号 | int | 否 | 是 | 否 | 否 | -| Salary | 工资 | float | 否 | 否 | 否 | 否 | -| Address | 家庭住址 | varchar(100) | 否 | 否 | 否 | 否 | - -3、添加记录 - -insert into department values(601,'软件技术系','软件技术等专业'), -(602,'网络技术系','多媒体技术等专业'),(603,'艺术设计系','广告艺术设计等专业'), -(604,'管理工程系','连锁经营管理等专业'); - -| **DepNo** | **DepName** | **DepNote** | -| --------- | ----------- | ------------------ | -| 601 | 软件技术系 | 软件技术等专业 | -| 602 | 网络技术系 | 多媒体技术等专业 | -| 603 | 艺术设计系 | 广告艺术设计等专业 | -| 604 | 管理工程系 | 连锁经营管理等专业 | - - - - - - -insert into teacher values(2001,'Tom','女','1970-01-10',602,4500,'四川省绵阳市'), -(2002,'Lucy','男','1983-12-18',601,2500,'北京市昌平区'), -(2003,'Mike','男','1990-06-01',604,1500,'重庆市渝中区'), -(2004,'James','女','1980-10-20',602,3500,'四川省成都市'),(2005,'Jack','男','1975-05-30',603,1200,'重庆市南岸区'); -| **Number** | **Name** | **Sex** | **Birth** | **DepNo** | **Salary** | **Address** | -| ---------- | -------- | ------- | ---------- | --------- | ---------- | ------------ | -| 2001 | Tom | 女 | 1970-01-10 | 602 | 4500 | 四川省绵阳市 | -| 2002 | Lucy | 男 | 1983-12-18 | 601 | 2500 | 北京市昌平区 | -| 2003 | Mike | 男 | 1990-06-01 | 604 | 1500 | 重庆市渝中区 | -| 2004 | James | 女 | 1980-10-20 | 602 | 3500 | 四川省成都市 | -| 2005 | Jack | 男 | 1975-05-30 | 603 | 1200 | 重庆市南岸区 | - -4、用SELECT语句查询Teacher表的所有记录。 - -```mysql - -```select * from teacher; - - - - - - -``` \ No newline at end of file -- Gitee From bd78bd400dd08960d5c6eb721e8675ea434117c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=AB=E9=9B=AA=E8=8E=B2=E7=9A=84=E4=BD=9C=E4=B8=9A?= <1653483984@qq.com> Date: Tue, 28 Feb 2023 22:44:27 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E9=97=AB=E9=9B=AA=E8=8E=B2=E7=9A=84?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...63\350\201\224\346\237\245\350\257\242.md" | 24 ------------------- 1 file changed, 24 deletions(-) diff --git "a/37 \351\227\253\351\233\252\350\216\262/20230227 \345\205\263\350\201\224\346\237\245\350\257\242.md" "b/37 \351\227\253\351\233\252\350\216\262/20230227 \345\205\263\350\201\224\346\237\245\350\257\242.md" index 223ece2..94a45bf 100644 --- "a/37 \351\227\253\351\233\252\350\216\262/20230227 \345\205\263\350\201\224\346\237\245\350\257\242.md" +++ "b/37 \351\227\253\351\233\252\350\216\262/20230227 \345\205\263\350\201\224\346\237\245\350\257\242.md" @@ -1,27 +1,3 @@ -# 1.笔记 - -## 关联查询 - -```sql -1,内连接:inner join ... on - -2、左连接:A left join B on - -(2)A表全部 - -(3)A表- A∩B - -3、右连接:A right join B on - -4、全外连接:full outer join ... on,但是mysql不支持这个关键字,mysql使用union(合并)结果的方式代替 - -(6)A表∪B表: (2) A表结果 union (4)B表的结果 - -(7)A∪B - A∩B (3)A表- A∩B结果 union (5)B表-A∩B结果 -``` - -# 2.作业 - ```sql create database zuoye2 charset utf8; use zuoye2; -- Gitee