From 0983545fa1a0ba3db9d3fadc1893baf17fbf9b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B0=B8=E6=B7=B3?= <2678158018@qq.com> Date: Wed, 22 Feb 2023 23:53:38 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...56\345\272\223\344\275\234\344\270\232.md" | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 "18 \345\276\220\346\260\270\346\267\263/20230222 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" diff --git "a/18 \345\276\220\346\260\270\346\267\263/20230222 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" "b/18 \345\276\220\346\260\270\346\267\263/20230222 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" new file mode 100644 index 0000000..f7c0763 --- /dev/null +++ "b/18 \345\276\220\346\260\270\346\267\263/20230222 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" @@ -0,0 +1,111 @@ +```mysql + + + +CREATE DATABASE test01_company CHARSET utf8; +USE test01_company; +CREATE TABLE offices( + officeCode INT, + city VARCHAR(30), + address VARCHAR(50), + country VARCHAR(50), + postalCode VARCHAR(25) +); +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) +); +ALTER TABLE employees MODIFY mobile VARCHAR(25) AFTER code; +ALTER TABLE employees CHANGE birth birthday DATE; +ALTER TABLE employees MODIFY sex CHAR(1); +ALTER TABLE employees DROP note; +ALTER TABLE employees ADD favoriate_activity VARCHAR(100); +ALTER TABLE employees RENAME employees_info; + + + +CREATE DATABASE test02db CHARSET utf8; +USE test02db; +CREATE TABLE pet( + name VARCHAR(20) , + owner VARCHAR(20) , + species VARCHAR(20), + sex CHAR(1) , + birth year, + death year +); +INSERT INTO pet VALUES ('Fluffy','harold','Cat','f','2003','2010'), ('Claws','gwen','Cat','m','2004',NULL), ('Butty',NULL,'Dog','f','2009',NULL), ('Fang','benny','Dog','m','2000',NULL), ('bowser','diane','Dog','m','2003','2009'), ('Chirpy',NULL,'Bird','f','2008',NULL); +ALTER TABLE pet ADD owner_birth DATE; +UPDATE pet SET owner='kevin' WHERE NAME='Claws'; +UPDATE pet SET owner='duck' WHERE species='dog' AND OWNER IS null; +SELECT*FROM pet WHERE OWNER IS null; +SELECT name,owner, death FROM pet WHERE species='cat' AND death IS NOT NULL; +DELETE FROM pet WHERE death is not null and species = 'Dog'; + + + + +CREATE DATABASE test03_company CHARSET utf8; +use test03_company; +create table department( + depid int primary KEY, + depname char(10) not null , + deinfo varchar(200) +); +CREATE TABLE employee ( +empid int PRIMARY KEY, +name VARCHAR(50), +sex enum('男','女') not null DEFAULT '男', +title VARCHAR(10), +birthday DATE, +depid int,FOREIGN key employee(depid) REFERENCES department(depid) on update cascade on delete set null +); +CREATE TABLE salary ( +empid INT PRIMARY KEY, +basesalary int, +titlesalary int , +deduction INT +); +ALTER TABLE salary ADD FOREIGN KEY(empid) REFERENCES employee(empid) ON UPDATE CASCADE ON DELETE CASCADE; +INSERT INTO department VALUES(111,'生产部',NULL),(222,'销售部',NULL),(333,'人事部','人力资源管理'); +INSERT INTO employee VALUES(1001,'张三','男','高级工程师','1975-1-1',111),(1002,'李四','女','助工','1985-1-1',111),(1003,'王五','男','工程师','1978-11-11',222),(1004,'张六','男','工程师','1999-1-1',222); +INSERT INTO salary VALUES( 1001 , 2200 , 1100 , 200 ),( 1002 ,1200,200,NULL),(1003,2900,700,200),(1004,1950,700,150); + + + +CREATE DATABASE test04_school CHARSET utf8; +use test04_school; +CREATE TABLE Department( +DepNo int(10) PRIMARY KEY not null UNIQUE key, +DepName VARCHAR(20) NOT null, +DepNote Varchar(50) +); +CREATE TABLE Teacher( +Number int PRIMARY KEY NOT null unique key, +Name VARCHAR(30) not null, +sex VARCHAR(4), +birth date, +DepNo int, FOREIGN KEY teacher(depno) REFERENCES Department(DepNo), +Salary FLOAT, +Address VARCHAR(100) +); +INSERT INTO Department VALUES (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,'重庆市南岸区'); +SELECT*FROM teacher; +``` + +查询全部要用 select*from 库名 + +查询部分要用 select 需要查询的信息 from 库名 + +如果查询要两个条件 可以在后面加 and 若值为空 可以填 信息 is null + +主键 primary key 外键 foreign key 库名(表名)reference 其他库名(对方主键)、 + -- Gitee From d60094936ab3b9bf1a4b107ef57021dc8cbc3e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B0=B8=E6=B7=B3?= <2678158018@qq.com> Date: Thu, 23 Feb 2023 22:45:39 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...56\345\272\223\344\275\234\344\270\232.md" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "18 \345\276\220\346\260\270\346\267\263/20230223 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" diff --git "a/18 \345\276\220\346\260\270\346\267\263/20230223 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" "b/18 \345\276\220\346\260\270\346\267\263/20230223 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" new file mode 100644 index 0000000..0d860fa --- /dev/null +++ "b/18 \345\276\220\346\260\270\346\267\263/20230223 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" @@ -0,0 +1,60 @@ +```sql +CREATE DATABASE goodbye CHARSET utf8; +USE goodbye; +CREATE TABLE employee( + id INT, + `name` VARCHAR(20), + sex VARCHAR(20), + tel VARCHAR(20), + addr VARCHAR(50), + salary FLOAT +); + +#添加信息 +INSERT INTO employee(id,`name`,sex,tel,addr,salary)VALUES +(10001,'张一一','男','13456789000','广东韶关',10010.58), +(10002,'刘小红','女','13454319000','广东江门',12010.21), +(10003,'李四','男','0751-1234567','广东佛山',10040.11), +(10004,'刘小强','男','0755-5555555','广东深圳',15010.23), +(10005,'王艳','男',NULL,'广东广州',14050.16); +SELECT*FROM employee where salary>12000 and salary<13000; +SELECT NAME FROM employee WHERE NAME LIKE '刘%'; +UPDATE employee SET addr='广东韶关' WHERE name='李四'; +SELECT NAME FROM employee WHERE NAME LIKE '%小%'; +SELECT*FROM employee WHERE salary>11000 AND sex='男'; +SELECT*FROM employee where tel is null; +SELECT*FROM employee WHERE (salary>12000 AND sex='男' ) OR (addr='广州' AND ADDr='广东深圳'); +SELECT name ,salary FROM employee; +``` + + + +```sql +CREATE DATABASE sever CHARSET utf8; +use sever; +CREATE TABLE `countries_info`( + `name` VARCHAR(100), + `continent` VARCHAR(100), + `area` INT, + population INT, + gdp BIGINT +); + +INSERT INTO countries_info VALUES +('Afghanistan','Asia',652230,25500100,20343000000), +('Albania','Europe',28748,2831741,12960000000), +('Algeria','Africa',2381741,37100000,188681000000), +('Andorra','Europe',468,78115,3712000000), +('Angola','Africa',1246700,20609294,100990000000); +SELECT name, area ,population FROM countries_info WHERE area>=3000000 or population>=25000000; +SELECT*FROM countries_info WHERE continent='asia'; +SELECT*FROM countries_info WHERE area<=10000 AND population<=100000; +SELECT*FROM countries_info WHERE NAME LIKE '%o%'; +SELECT*FROM countries_info WHERE gdp>10000000000; +SELECT name 国家,population 人口,gdp gdp值,gdp/population 人均gdp值 FROM countries_info ; +SELECt * ,gdp/population 人均gdp值 from countries_info WHERE gdp/population<1000; +SELECT name 国家名,area 面积,population 人口,area/population 人均国土面积值 FROM countries_info; +``` + + + -- Gitee From 9d622f17d6d6a398eb2f1cab5511e36f057f14aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B0=B8=E6=B7=B3?= <2678158018@qq.com> Date: Thu, 23 Feb 2023 22:52:58 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...56\345\272\223\344\275\234\344\270\232.md" | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git "a/18 \345\276\220\346\260\270\346\267\263/20230223 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" "b/18 \345\276\220\346\260\270\346\267\263/20230223 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" index 0d860fa..087ac93 100644 --- "a/18 \345\276\220\346\260\270\346\267\263/20230223 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" +++ "b/18 \345\276\220\346\260\270\346\267\263/20230223 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" @@ -52,9 +52,33 @@ SELECT*FROM countries_info WHERE area<=10000 AND population<=100000; SELECT*FROM countries_info WHERE NAME LIKE '%o%'; SELECT*FROM countries_info WHERE gdp>10000000000; SELECT name 国家,population 人口,gdp gdp值,gdp/population 人均gdp值 FROM countries_info ; -SELECt * ,gdp/population 人均gdp值 from countries_info WHERE gdp/population<1000; +SELECt *,gdp/population 人均gdp值 from countries_info WHERE gdp/population<1000; SELECT name 国家名,area 面积,population 人口,area/population 人均国土面积值 FROM countries_info; ``` +区间范围:between x and y + not between x and y +集合范围:in (x,x,x) + not in(x,x,x) + between ... and ... 结果包含两端的边界 + +大于:> +小于:< +大于等于:>= +小于等于:>= +等于:= 不能用于null判断 +不等于:!= 或 <> 不能用于null判断 +判断是null 用 is null 或 用 <=> null +判断不是null is not null + +加:+ + 在MySQL +就是求和,没有字符串拼接 +减:- +乘:* +除:/ div(只保留整数部分) + div:两个数相除只保留整数部分 + /:数学中的除 +模:% mod + -- Gitee From 9ba69514b6a0951fdaf07b923a503d50dedfd580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B0=B8=E6=B7=B3?= <2678158018@qq.com> Date: Thu, 2 Mar 2023 12:57:32 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...56\345\272\223\344\275\234\344\270\232.md" | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 "18 \345\276\220\346\260\270\346\267\263/20230301 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" diff --git "a/18 \345\276\220\346\260\270\346\267\263/20230301 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" "b/18 \345\276\220\346\260\270\346\267\263/20230301 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" new file mode 100644 index 0000000..f9855c2 --- /dev/null +++ "b/18 \345\276\220\346\260\270\346\267\263/20230301 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" @@ -0,0 +1,141 @@ +CREATE DATABASE school charset utf8; +use school; +CREATE TABLE student( +sno VARCHAR(20) not null PRIMARY KEY, +sname VARCHAR(20) not null, +ssex VARCHAR(20) not null, +sbirthday datetime, +class VARCHAR (20) +); + +CREATE TABLE Course( +cno VARCHAR (20) not NULL PRIMARY KEY, +cname VARCHAR (20) not null , +tno VARCHAR(20) not null, +FOREIGN KEY (tno) REFERENCES teacher(tno) +); +set FOREIGN_key_checks=0; + +CREATE TABLE score( +sno VARCHAR(20) not null ,FOREIGn key (sno) REFERENCES student(sno), +cno VARCHAR (20) not null ,FOREIGN KEY (cno) REFERENCES course(cno), +degree DECIMAL(4,1), +PRIMARY key(sno,cno) +); + +CREATE TABLE teacher( +tno VARCHAR (20) not null PRIMARY KEY, +tname VARCHAR (20) not NULL, +tsex VARCHAR (20) COMMENT'教工性别' not null, +tbirthday datetime, +prot VARCHAR (20), +depart VARCHAR (20) not null +); +SELECT * FROM teacher; +INSERT INTO student VALUES(108,'曾华','男', '1977-9-1', '95033'), +(105,'匡明','男','1975-10-2', '95031'), +(107,'王丽','女','1976-1-23','95033'), +(101,'李军','男','1976-2-20','95033'), +(109,'王芳','女','1975-2-10','95031'), +(103,'陆君','男','1974-6-3','95031'); +INSERT INTO course VALUES (3-105,'计算机导论',825), +(3-245,'操作系统',804), +(6-166,'数字电路',856), +(9-888,'高等数学',831); +INSERT INTO score VALUES(103,'3-245',86), +(105,'3-245',75), +(109,'3-245',68), +(103,'3-105',92), +(105,'3-105',88), +(109,'3-105',76), +(101,'3-105',64), +(107,'3-105',91), +(108,'3-105',78), +(101,'6-166',85), +(107,'6-166',79), +(108,'6-166',81); +INSERt INTo teacher VALUES(804,'李诚','男','1958-12-2','副教授','计算机系'), +(856,'张旭','男','1969-3-12','讲师','电子工程系'), +(825,'王萍','女','1972-5-5','助教','计算机系'), +(831,'刘冰','女','1977-8-14','助教','电子工程系'); +SELECT MAX(degree),sno,cno FROM score; +-- set @@GLOBAL.sql_mode=''; +-- +-- set sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; + +select Student.Sname,Score.Cno,Score.Degree from +Score inner join Student on Student.Sno=Score.Sno; +-- 3.查询所有学生的Sno、Cname和Degree列。 +select Score.Sno,Course.Cname,Score.Degree FROM +Course inner join Score on Course.Cno=Score.Cno; +-- 4.查询所有学生的Sname、Cname和Degree列。 +select Student.Sname,Course.Cname,Score.Degree FROM +Student inner join Score inner join Course +on Score.Sno=Student.Sno and Score.Cno=Course.Cno; +-- 5.查询“95033”班学生的平均分。 +select round(sum(Degree) / count(Class),1) 成绩 from Student inner join Score on +Score.Sno=Student.Sno where Class='95033'; +-- 6.查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。 +select * from Score where Cno='3-105' and degree>(sno='109'); +-- 7.查询score中选学多门课程的同学中分数为非最高分成绩的记录。 + +-- 8.查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。 +select * from Student inner join Score inner join Course on +Student.Sno=Score.Sno and Score.Cno=Course.Cno where +(Score.Sno='109') (select avg(Degree) from Score); +-- 17.查询所有任课教师的Tname和Depart. +select tname,Depart from Teacher inner join Course on +Course.Tno=Teacher.Tno +where +Teacher.Tno = Course.Tno; +-- 18.查询所有未讲课的教师的Tname和Depart. +select tname,Depart from Teacher inner join Course on +Course.Tno=Teacher.Tno +where +not (Teacher.Tno = Course.Tno); +-- 19.查询“男”教师及其所上的课程。 +select Tname,Cname from Teacher inner join Course on +Teacher.Tno=Course.Tno +where +Tsex='男'; +-- 20.查询最高分同学的Sno、Cno和Degree列。 +select sno,cno,Degree from Score +WHERE +(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 Degree from Course inner join Score inner join Student on +Course.Cno=Score.Cno and Score.Sno=Student.Sno +where +Ssex='男' +and +Cname=(select Cname from Course where Cname='计算机导论') ; -- Gitee From ba628dab0d02dbfe01f34197b1acabdc2be5cb5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B0=B8=E6=B7=B3?= <2678158018@qq.com> Date: Thu, 9 Mar 2023 12:56:53 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E7=AC=AC=E5=9B=9B=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...56\345\272\223\344\275\234\344\270\232.md" | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 "18 \345\276\220\346\260\270\346\267\263/20230309 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" diff --git "a/18 \345\276\220\346\260\270\346\267\263/20230309 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" "b/18 \345\276\220\346\260\270\346\267\263/20230309 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" new file mode 100644 index 0000000..4600d4a --- /dev/null +++ "b/18 \345\276\220\346\260\270\346\267\263/20230309 \346\225\260\346\215\256\345\272\223\344\275\234\344\270\232.md" @@ -0,0 +1,68 @@ +```mysql +CREATE database if not EXISTS student charset utf8; +use student; +CREATE TABLE stuinto( +stuno VARCHAR(20), +stuname VARCHAR(10), +stusex enum('男','女'), +stuage int, +stuaddress VARCHAR(50), +stuseat INT +); +CREATE TABLE stuexam( +examno int, +stuno VARCHAR(20), +writtenexam int, +labexam int +); +CREATE TABLE stumarks( +examno int, +stuid VARCHAR(20), +score int +); +-- 在如图的数据表上完成以下题目 +insert into stuinto VALUES ('s2501','张秋利','男',20,'美国硅谷',1),('s2502','李斯文','女',18,'湖北武汉',2),('s2503','马文才','男',18,'湖南长沙',3),('s2504','欧阳俊雄','女',21,'湖北武汉',4),('s2505','梅超风','男',16,'湖北武汉',5),('s2506','陈旋风','男',19,'美国硅谷',6); +INSERT into stuexam VALUES(1,'s2501',50,70),(2,'s2502',60,65),(3,'s2503',86,70),(4,'s2504',40,80),(5,'s2505',70,85),(6,'s2506',85,90); +INSERT into stumarks VALUES(1,'s2501',88),(2,'s2501',92),(3,'s2501',53),(4,'s2502',60),(5,'s2502',99),(6,'s2503',82); +SELECT *FROM stumarks; +SELECT * FROM stuinto; +SELECT * FROM stuexam; +DROP TABLE stumarks; +-- 1.查询出年龄比班上平均年龄大的学生的信息 +SELECT * FROM stuinto WHERE stuage>(SELECT avg(stuage)FROM stuinto) ; +-- 2.查询出每个学生的学号,姓名,性别和选修课程的最高分(stuMarks) +SELECT * FROM (SELECT stuid,max(score) FROM stumarks GROUP BY stuid) stumarks RIGHT JOIN stuinto on stumarks.stuid = stuinto.stuno; +-- 3.查询出每个学生的学号,姓名,性别和考试平均分(stuExam) +select stuinto.stuno,stuname,stusex,round((writtenexam+labexam)/2,2) from stuinto left join stuExam on stuinto.stuno=stuexam.stuno group by stuinto.stuno; +-- 4.查询性别是男并且年龄大于等于20的学生的信息(用两种方法实现:普通查询和子查询) +SELECT * FROM stuinto WHERE stuage>=20 and stusex='男'; +SELECT * FROM stuinto WHERE stuage in (SELECT stuage FROM stuinto WHERE stuage>=20) and stusex='男'; +-- 5.查询出年龄比所有男生年龄都大的女生的信息 +SELECT * FROM stuinto WHERE stuage not in (SELECT stuage FROM stuinto WHERE stusex='男') and stusex='女'; +-- 6.查询出所有选修课程都及格的学生的信息 (stuMarks) +SELECT * FROM stumarks right join stuinto on stumarks.stuid=stuinto.stuno WHERE score>=60 GROUP BY stuid; +-- 7.查询出参加考试的学生的信息(用表连接,in二种方法做)(stuMarks) +SELECT * FROM stuinto left JOIN stumarks on stumarks.stuid=stuinto.stuno WHERE score is not null GROUP BY stuno; + +select * from stuinto left join stumarks on stuinto.stuno=stumarks.stuid WHERE stuno not in (select score from stumarks) GROUP BY stuno ; +-- 8.查询出没有参加考试的学生的信息(用表连接,in二种方法做)(stuMarks) +SELECT * FROM stuinto left JOIN stumarks on stumarks.stuid=stuinto.stuno WHERE score is null; + +select * from stuinto left join stumarks on stuinto.stuno=stumarks.stuid WHERE stuno not in (select score from stumarks) GROUP BY stuno; +-- 9.将有一门成绩成绩大于90分的学生的基本信息查询出来(stuMarks) +SELECT * FROM stumarks RIGHT JOIN stuinto on stumarks.stuid=stuinto.stuno WHERE score>90; +-- 10.查询出平均成绩在80分以上的学生的基本信息(stuMarks) +SELECT * FROM stuinto left JOIN stumarks on stuinto.stuno=stumarks.stuid WHERE score not IN(SELECT avg(score) FROM stumarks )GROUP BY stuid; + +-- 11.查询出某同学所有考试成绩比“张秋利”同学所有分数都高的学生基本信息(stuMarks) +select stuinto.* from stuinto left join stumarks on stuinto.stuno=stumarks.stuid where score > (select score from stumarks where stuid='s2501') group by stuid; +-- 12.查询出某同学所有考试成绩只需要比“张秋利”同学某个分数高的学生基本信息(stuMarks) +select stuinto.* from stuinto ,(select stuid from stumarks where stuid!='s2501' group by stuid having max(score)>(select min(score) from stumarks where stuid='s2501')) b where stuinto.stuno=b.stuid; + +-- 13.查询班上比所有男生年龄都要大的女生的信息 +select * from stuinto where stuage not in (select stuage from stuinfo where stusex='男') and stusex='女'; + +-- 14.查询出只要比某个男生年龄大的女生的信息 +select * from stuinto where stuage>(select min(stuage) from stuinto where stusex='男') and stusex='女'; +``` + -- Gitee