diff --git "a/17 \345\221\250\345\257\214/20230219 mysql\347\254\224\350\256\260.md" "b/17 \345\221\250\345\257\214/20230219 mysql\347\254\224\350\256\260.md" index 513fe91faf93c80546ff42a82379b9b282c259af..4691ee7b139182bf70dd8509855d71d5e0d3c462 100644 --- "a/17 \345\221\250\345\257\214/20230219 mysql\347\254\224\350\256\260.md" +++ "b/17 \345\221\250\345\257\214/20230219 mysql\347\254\224\350\256\260.md" @@ -230,4 +230,39 @@ delete from 表名称; ```mysql truncate 表名称; -``` \ No newline at end of file +``` + +## 约束 + +非空约束: + +~~~mysql +not null; +~~~ + +默认约束: + +~~~mysql +default ‘内容’; +~~~ + +主键约束: + +~~~mysql +primary key; +~~~ + +唯一约束: + +~~~mysql +unique key; +~~~ + +自增约束: + +~~~mysql +auto-inck ement primary key; +~~~ + +自增约束给null和0时会自增,指定一个值时就是你指定的数 + diff --git "a/17 \345\221\250\345\257\214/20230222\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232.md" "b/17 \345\221\250\345\257\214/20230222\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..b6a8946d186611f25ce604f650bf54471e878e9d --- /dev/null +++ "b/17 \345\221\250\345\257\214/20230222\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,313 @@ +## 第1题 + +1、创建数据库test01_company + +create database test01_company charset utf8; +use test01_company; + +2、创建表格offices + +create table offices( +officecode int, +city varchar(30), +address varchar(50), +county varchar(50), +postalcoda varchar(25) +); + +| 字段名 | 数据类型 | +| ---------- | ----------- | +| officeCode | int | +| city | varchar(30) | +| address | varchar(50) | +| country | varchar(50) | +| postalCode | varchar(25) | + +3、创建表格employees + +create table employees( +empnum int, +lastname varchar(50), +firstname varchar(50), +mobile varchar(25), +code int, +jobtitle varchar(50), +birth date, +note varchar(255), +sex varchar(5) +); + +| 字段名 | 数据类型 | +| ------------- | ---------------------------- | +| 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) | + +**要求4:**将表employees的mobile字段修改到code字段后面。 + +ALTER TABLE employees MODIFY mobile VARCHAR(25) AFTER `code` ; + +**要求5:**将表employees的birth字段改名为birthday; + +ALTER TABLE employees CHANGE mobile birthday date; + +**要求6:**修改sex字段,数据类型为char(1)。 + +ALTER TABLE employees MODIFY sex char(1); + +**要求7:**删除字段note; + +ALTER TABLE employees DROP note; + +**要求8:**增加字段名favoriate_activity,数据类型为varchar(100); + +ALTER TABLE employees add favoriate_activity VARCHAR(100); + +**要求9:**将表employees的名称修改为 employees_info + +```mysql +ALTER TABLE employees RENAME employees_info; +``` + + + +## 第2题 + +1、创建数据库test02db + +CREATE database text02db; + +2、创建表格pet + +CREATE TABLE pet( +`name` varchar(20), +`owner` varchar(20), +species varchar(20), +sex char(1), +birth year, +death year +); + +| 字段名 | 字段说明 | 数据类型 | +| ------- | -------- | ----------- | +| name | 宠物名称 | varchar(20) | +| owner | 宠物主人 | varchar(20) | +| species | 种类 | varchar(20) | +| sex | 性别 | char(1) | +| birth | 出生日期 | year | +| death | 死亡日期 | year | + +3、添加记录 + +INSERT into pet 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); + +| 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 | | + +4、 添加字段主人的生日owner_birth。 + +ALTER TABLE pet add owner_birth date; + +5、 将名称为Claws的猫的主人改为kevin + +UPDATE pet SET `owner`='kevin' WHERE `name`='Claws'; + +6、 将没有死的狗的主人改为duck + +update pet set `owner`='duck' WHERE `death`IS NULL; + +7、 查询没有主人的宠物的名字; + +SELECT `name` FROM pet where `owner` IS null; + +8、 查询已经死了的cat的姓名,主人,以及去世时间; + +select `name`,`owner`,death from pet WHERE species='Cat'; + +9、 删除已经死亡的狗 + +delete from pet where species='Dog' and death='2009'; + +10、查询所有宠物信息 + +```mysql + +select * from pet; +``` + +## 第3题 + +1、创建数据库: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) +) +``` + +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)。其中雇员编号为主键。 + +3、给工资表(salary)的雇员编号(empid)增加外键约束,外键约束等级为(on update cascade 和on delete cascade) + +create table salary( +empid int primary key, +basesalary double, +titlesalary double, +deduction double, +foreign key(empid) references employee(empid) + +); + +4、添加数据如下: + +部门表: + +INSERT INTO department(depid,depname,deinfo) VALUES (111,'生产部',NULL),(222,'销售部',NULL),(333,'人事部','人力资源管理'); + +| 部门编号 | 部门名称 | 部门简介 | +| -------- | -------- | ------------ | +| 111 | 生产部 | Null | +| 222 | 销售部 | Null | +| 333 | 人事部 | 人力资源管理 | + + 雇员表: + +INSERT into employee(empid,`name`,sex,title,birthday,depid) VALUES(1001,'张三','男','高级工程师','1975-1-1',111),(1002,'李四','女','助工','1985-1-1',111),(1003,'王五','男','工程师','1978-11-11',222),(1004,'张六','男','工程师','1999-1-1',222); + +| 雇员编号 | 姓名 | 性别 | 职称 | 出生日期 | 所在部门编号 | +| -------- | ---- | ---- | ---------- | ---------- | ------------ | +| 1001 | 张三 | 男 | 高级工程师 | 1975-1-1 | 111 | +| 1002 | 李四 | 女 | 助工 | 1985-1-1 | 111 | +| 1003 | 王五 | 男 | 工程师 | 1978-11-11 | 222 | +| 1004 | 张六 | 男 | 工程师 | 1999-1-1 | 222 | + + 工资表: + +INSERT INTO salary(empid,basesalary,titlesalary,deduction) VALUES(1001,2200,1100,200),(1002,1200,200,NULL),(1003,2990,700,200),(1004,1950,700,150); + +| 雇员编号 | 基本工资 | 职务工资 | 扣除 | +| -------- | -------- | -------- | ---- | +| 1001 | 2200 | 1100 | 200 | +| 1002 | 1200 | 200 | NULL | +| 1003 | 2900 | 700 | 200 | +| 1004 | 1950 | 700 | 150 | + + + +## 第4题 + +1、创建一个数据库:test04_school + +CREATE DATABASE text04_scgool; + +2、创建如下表格 + +表1 Department表的定义 + +CREATE TABLE Department( +DepNo int(10) PRIMARY KEY NOT NULL UNIQUE, +DepName VARCHAR(20) NOT NULL, +DepNote VARCHAR(50) +); + +| **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | +| ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | +| DepNo | 部门号 | int(10) | 是 | 否 | 是 | 是 | +| DepName | 部门名称 | varchar(20) | 否 | 否 | 是 | 否 | +| DepNote | 部门备注 | Varchar(50) | 否 | 否 | 否 | 否 | + +表2 Teacher表的定义 + + create table Teacher( +Number int primary key not null unique, +`Name` varchar(30) not null, +Sex VARCHAR(4), Birth date, +DepNo int, +Salary float, +Address VARCHAR(100), +foreign key(DepNo) references Department(DepNo) +); + +| **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | +| ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | +| 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,'管理工程系','连锁经营管理等专业'); + + + +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,'重庆市南岸区'); + +| **DepNo** | **DepName** | **DepNote** | +| --------- | ----------- | ------------------ | +| 601 | 软件技术系 | 软件技术等专业 | +| 602 | 网络技术系 | 多媒体技术等专业 | +| 603 | 艺术设计系 | 广告艺术设计等专业 | +| 604 | 管理工程系 | 连锁经营管理等专业 | + +| **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; +``` + + + + + diff --git "a/17 \345\221\250\345\257\214/20230223\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260.md" "b/17 \345\221\250\345\257\214/20230223\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..8667afe5cc7d7e4bcfb84af299542d56dce63570 --- /dev/null +++ "b/17 \345\221\250\345\257\214/20230223\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232\345\222\214\347\254\224\350\256\260.md" @@ -0,0 +1,267 @@ +## DQL + +结果去重 + +### distinct + +只能放在第一个字段前面,一次只支持一列字段 + +~~~ +select distinct 字段列表 from 表名称 where 条件 +~~~ + +### 别名 + +select 字段 别名,字段 别名 from 表名 别名; + +列的别名有空格时,加双引号,没有空格双引号可加可不加 + +表的别名不用加双引号,表的别名不能有空格 + +### 模糊查询 + +### like + +%;代表任意个字符 + +—;代表一个字符,两个下划线就是两个字符 + +### 逻辑查询 + +### xor + +两者只能满足其中一个,不能同时满足,不能同时不满足。 + +## 运算符 + +div (保留整数部分) + +安全等于 <=> 可以用于null的运算 + +模,% (取余) + +不等于,!= 或 <> 不能用于null判断 + +## 区间 + +区间范围 + +~~~mysql +between x and y +~~~ + +不在这区间 + +~~~sql +not between x and y +~~~ + +集合范围 + +~~~sql +in (x,y,z),有其中一个就行 +not in(x,y,z),不在这其中 +~~~ + + + + + +## 第1题:员工表 + +```mysql +drop table if exists `employee`; +#创建employee表 +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); +``` + + + +| **id** | **name** | **sex** | **tel** | **addr** | **salary** | +| ------ | -------- | ------- | ------------ | -------- | ---------- | +| 10001 | 张一一 | 男 | 13456789000 | 广东韶关 | 10010.58 | +| 10002 | 刘小红 | 女 | 13454319000 | 广东江门 | 12010.21 | +| 10003 | 李四 | 男 | 0751-1234567 | 广东佛山 | 10040.11 | +| 10004 | 刘小强 | 男 | 0755-5555555 | 广东深圳 | 15010.23 | +| 10005 | 王艳 | 女 | NULL | 广东广州 | 14050.16 | + +**要求1:**查询出薪资在12000~13000之间的员工信息。 + +~~~sql +select * from employee where salary between 12000 and 13000; +~~~ + + + +**要求2:**查询出姓“刘”的员工的工号,姓名,家庭住址。 + +~~~sql +select id,name,addr from employee where name like "刘%"; +~~~ + +**要求3:**将“李四”的家庭住址改为“广东韶关” + +~~~sql +update employee set addr = '广东韶关' where name = '李四'; +~~~ + + + +**要求4:**查询出名字中带“小”的员工 + +~~~SQL +select * from employee where name like "%小%" +~~~ + + + +**要求5:**查询出薪资高于11000的男员工信息 + +~~~SQL +select * from employee where salary > 11000 and sex = '男'; +~~~ + + + +**要求6:**查询没有登记电话号码的员工 + +~~~SQL +select * from employee where tel is null; +~~~ + + + +**要求7:**查询薪资高于12000或者家是广东深圳、广州的男员工 + +~~~SQL +select * from employee where salary > 12000 and sex = '男' or addr in('广东深圳','广东广州') and sex = '男'; +~~~ + + + +**要求8:**查询每个员工的年薪,显示“姓名、年薪” + +```mysql +select name '姓名',salary*12 年薪 from employee; +``` + +## 第2题:国家信息表 + +countries_info表中存储了国家名称、所属大陆、面积、人口和 GDP 值。 + +```mysql +DROP TABLE IF EXISTS `countries_info`; +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); +``` + +表数据样例: + +```mysql ++-------------+-----------+---------+------------+--------------+ +| name | continent | area | population | gdp | ++-------------+-----------+---------+------------+--------------+ +| 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 | ++-------------+-----------+---------+------------+--------------+ +``` + +**要求1:** 查询大国 的国家名称、人口和面积。 + +~~~SQL +select name,area,population from countries_info where population >= 25000000 or +area >= 3000000; +~~~ + + + +如果一个国家满足下述两个条件之一,则认为该国是 大国 : + +- 面积至少为 300万平方公里(即,3000000 km2) + +- 人口至少为 2500 万(即 25000000) + +**要求2:**查询属于亚洲的国家名称、所属大陆、面积、人口和 GDP 值 + +~~~SQL +select * from countries_info where continent = 'Asia'; +~~~ + + + +**要求3:**查询国土面积不足1万平方公里且人口不走10万人的国家信息 + +~~~SQL +select * from countries_info where area < 10000 and population < 100000; +~~~ + + + +**要求4:**查询国家名字中包含“o“字母的国家信息 + +~~~SQL +select * from countries_info where continent like "%o%"; +~~~ + + + +**要求5:**查询GDP值超过10000000000的国家信息 + +~~~SQL +select * from countries_info where gdp > 10000000000; +~~~ + + + +**要求6:**查询每个国家的人均贡献GDP值(GDP/人口总数)并显示为“国家名、人口、GDP值、人均贡献GDP值” + +~~~SQL +select name,population,gdp,gdp/population 人均贡献GDP值 from countries_info; +~~~ + + + +**要求7:**查询人均贡献GDP值低于1000的国家信息。 + +~~~SQL +select * from countries_info where gdp/population < 1000; +~~~ + + + +**要求8:**查询每个国家的人均国土面积(面积/人口总数)并显示为“国家名、面积、人口、人均国土面积值” + +```mysql +select name,area,population,area/population 人均国土面积值 from countries_info; +``` + diff --git "a/17 \345\221\250\345\257\214/20230307 \347\254\254\345\233\233\346\254\241\344\275\234\344\270\232.md" "b/17 \345\221\250\345\257\214/20230307 \347\254\254\345\233\233\346\254\241\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..1d741f825856a30923d13542da695e564dafe0ef --- /dev/null +++ "b/17 \345\221\250\345\257\214/20230307 \347\254\254\345\233\233\346\254\241\344\275\234\344\270\232.md" @@ -0,0 +1,110 @@ +### 笔记 + +##### 子查询 + +- 嵌套在其他SQL语句中的查询语句。 +- 子查询通常先运行,所以要用()包裹起来。 +- 子查询的运行结果,可以作为其他语句的条件,数据源等。 + +##### 子查询分三种形式 + + select 1 from 2 where 3 + +1.放在select后面 + +2.放在where/having后面 + +3.放在from后面,子查询当做一个临时的表使用,必须要给别名。 + +##### where或having后的子查询,其子查询的结果有三种形式 + +1.单列单个值,可以直接使用比较运算符 + +2.单列多个值,可以使用 in ,not in 进行比较 + +3.单列多个值,可以使用比较运算符,搭配any,all,等关键字与查询结果进行比较 + +##### 子查询结果是单列,可以放在select参与运算,或者是作为字段,也可以放在where / having后当条件。 + +##### 子查询结果是多列,多个值,只能放在from后面当临时表使用,并且必须取别名。 + +### 作业 + +~~~ mysql +create database text1 charset utf8; +use text1; +create table stuinfo( +stuNO varchar(10) primary key, +stuName varchar(10), +stuSex varchar(5), +stuAge double, +stuAddress varchar(20), +stuSeat int auto_increment unique +); +create table stuExam( +examNo int primary key, +stuNO varchar(10), +writtenExam varchar(10), +labExam double, +foreign key(stuNo) references stuinfo(stuNo) +); +create table stuMarks( +examNO int, +stuID varchar(10), +score double, +foreign key(examNO) references stuExam(examNO) +); +insert into stuinfo 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); +-- 1.查询出年龄比班上平均年龄大的学生的信息 +select * from stuinfo where stuAge>(selectavg(stuAge) from stuinfo); +-- 2.查询出每个学生的学号,姓名,性别和选修课程的最高分(stuMarks) +select t.stuNO,t.stuName,t.stuAge,max(score) from stumarks s left join stuinfo t on s.stuID=t.stuNO group by s.stuID; +-- 3.查询出每个学生的学号,姓名,性别和考试平均分(stuExam) +select avg(writtenExam+labExam) from stuexam right join stuinfo on stuexam.stuNO=stuinfo.stuNO GROUP BY stuexam.stuNO; +-- 4.查询性别是男并且年龄大于等于20的学生的信息(用两种方法实现:普通查询和子查询) +-- 普通查询 +select * from stuinfo where stusex='男' and stuage>=20; +-- 子查询 +select * from stuinfo where stuage=(select stuage from stuinfo where stusex='男' and stuage>=20); +-- 5.查询出年龄比所有男生年龄都大的女生的信息 +select stuSex,max(stuAge) from stuinfo where stuSex='女' and stuAge> all(select stuAge from stuinfo where stuSex ='男'); +-- 6.查询出所有选修课程都及格的学生的信息 (stuMarks) +select t.stuNO,t.stuName,t.stuAge,max(score) from stumarks s left join stuinfo t on s.stuID=t.stuNO group by s.stuID; +-- 7.查询出参加考试的学生的信息(用表连接,in二种方法做)(stuMarks) +select * from stuinfo a left join stumarks c on a.stuNO=c.stuID where stuID is NULL; +-- 8.查询出没有参加考试的学生的信息(用表连接,in二种方法做)(stuMarks) +select * from stuinfo a left join stumarks c on a.stuNO=c.stuID where a.stuNO not in (select stuID from stumarks group by stuID); +-- 9.将有一门成绩成绩大于90分的学生的基本信息查询出来(stuMarks) +select * from stuinfo left join stumarks on stuinfo.stuNO=stumarks.stuID where score>90; +-- 10.查询出平均成绩在80分以上的学生的基本信息(stuMarks) +select * from stuinfo left join stumarks on stuinfo.stuNO=stumarks.stuID where score>(select avg(score) from stumarks) +-- 11.查询出某同学所有考试成绩比“张秋利”同学所有分数都高的学生基本信息(stuMarks) +select * from stuinfo left join stumarks on stuinfo.stuNO=stumarks.stuID where stumarks.score > any(select score from stumarks where stumarks.stuID='s2501' ) and stuinfo.stuName != '张秋利' +-- 12.查询出某同学所有考试成绩只需要比“张秋利”同学某个分数高的学生基本信息(stuMarks) +select * from stuinfo left join stumarks on stuinfo.stuNO=stumarks.stuID where stumarks.score > any(select score from stumarks where stumarks.stuID='s2501' ) and stuinfo.stuName != '张秋利' +-- 13.查询班上比所有男生年龄都要大的女生的信息 +select stuSex,max(stuAge) from stuinfo where stuSex='女' and stuAge> all(select stuAge from stuinfo where stuSex ='男'); +-- 14.查询出只要比某个男生年龄大的女生的信息 +select * from stuinfo where stusex = '女' and stuage > (select min(stuage) from stuinfo where stusex = '男'); +~~~ +