From aff19acd3d43ab14a88d46f87ed112a27317cbd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8F=AD=E9=98=B3=E4=B8=BD?= <2431466589@qq.com> Date: Thu, 23 Feb 2023 12:04:34 +0800 Subject: [PATCH 1/3] =?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 --- ...L\347\232\204\347\272\246\346\235\237.txt" | 285 ++++++++++++++++++ 1 file changed, 285 insertions(+) create mode 100644 "37 \346\217\255\351\230\263\344\270\275/20230222 MySQL\347\232\204\347\272\246\346\235\237.txt" diff --git "a/37 \346\217\255\351\230\263\344\270\275/20230222 MySQL\347\232\204\347\272\246\346\235\237.txt" "b/37 \346\217\255\351\230\263\344\270\275/20230222 MySQL\347\232\204\347\272\246\346\235\237.txt" new file mode 100644 index 0000000..59d7ec1 --- /dev/null +++ "b/37 \346\217\255\351\230\263\344\270\275/20230222 MySQL\347\232\204\347\272\246\346\235\237.txt" @@ -0,0 +1,285 @@ +## 第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) | | | +| ); | | | +| -- **要求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 column 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 charset utf8; +use test02db; +-- 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 | | +| desc pet; +| -- 4、 添加字段主人的生日owner_birth。 +| alter table pet add owner_birth date; +| -- 5、 将名称为Claws的猫的主人改为kevin +| update pet set owner='kevin' where name='Claws'and species='Cat'; +| -- 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'; +| -- 9、 删除已经死亡的狗 +| delete from pet where species='Dog' and death is not null; +| -- 10、查询所有宠物信息 +| select * from pet; + + +-- ## 第3题 + +-- 1、创建数据库:test03_company +create database test03_company charset utf8; +use test03_company ; +-- 2、在此数据库下创建如下3表,数据类型,宽度,是否为空根据实际情况自己定义。 +-- A. 部门表(department):部门编号(depid),部门名称(depname),部门简介(deinfo);其中部门编号为主键。 +-- create table department( +-- depid int primary key auto_increment, +-- depname char(10) not null unique key, +-- deinfo varchar(200) +-- ); +create table department( +depid int primary key auto_increment, +depname varchar(50) not null unique key, +deinfo varchar(200) not null +); +alter table department modify deinfo varchar(100); +-- B. 雇员表(employee):雇员编号(empid),姓名(name),性别(sex),职称(title),出生日期(birthday),所在部门编号(depid);其中 +-- + +-- * 雇员编号为主键; +-- * 部门编号为外键,外键约束等级为(on update cascade 和on delete set null); + +-- * 性别默认为男; +-- 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) +-- ); + + create table employee( + empid int primary key auto_increment, + name varchar(50) not null, + sex enum('男','女') not null default '男', + title varchar(10), + birthday date, + depid int , + foreign key (depid) 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 auto_increment, +foreign key (empid) references employee(empid), +basesalary int, +titlesalary int, +deduction int +); + +-- 4、添加数据如下: +-- 部门表: +-- | 部门编号 | 部门名称 | 部门简介 | +-- | -------- | -------- | ------------ | +-- | 111 | 生产部 | Null | +-- | 222 | 销售部 | Null | +-- | 333 | 人事部 | 人力资源管理 | +insert into department values +(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 | +insert into employee values +(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 | +insert into salary values +(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、创建如下表格 +-- +-- 表1 Department表的定义 +-- +-- | **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | +-- | ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | +-- | DepNo | 部门号 | int(10) | 是 | 否 | 是 | 是 | +-- | DepName | 部门名称 | varchar(20) | 否 | 否 | 是 | 否 | +-- | DepNote | 部门备注 | Varchar(50) | 否 | 否 | 否 | 否 | +create table Department( +DepNo int(10) primary key auto_increment not null unique key, +DepName varchar(20) not null, +DepNote varchar(50) +); +-- +-- 表2 Teacher表的定义 +-- +-- | **字段名** | **字段描述** | **数据类型** | **主键** | **外键** | **非空** | **唯一** | +-- | ---------- | ------------ | ------------ | -------- | -------- | -------- | -------- | +-- | Number | 教工号 | int | 是 | 否 | 是 | 是 | +-- | Name | 姓名 | varchar(30) | 否 | 否 | 是 | 否 | +-- | Sex | 性别 | varchar(4) | 否 | 否 | 否 | 否 | +-- | Birth | 出生日期 | date | 否 | 否 | 否 | 否 | +-- | DepNo | 部门号 | int | 否 | 是 | 否 | 否 | +-- | Salary | 工资 | float | 否 | 否 | 否 | 否 | +-- | Address | 家庭住址 | varchar(100) | 否 | 否 | 否 | 否 | +create table Teacher( +Number int primary key not null unique key auto_increment, +Name varchar(30) not null, +Sex varchar(4), +Birth date, +DepNo int, +foreign key (DepNo) references Department(DepNo), +Salary float, +Address varchar(100) +); + +-- 3、添加记录 +-- +-- | **DepNo** | **DepName** | **DepNote** | +-- | --------- | ----------- | ------------------ | +-- | 601 | 软件技术系 | 软件技术等专业 | +-- | 602 | 网络技术系 | 多媒体技术等专业 | +-- | 603 | 艺术设计系 | 广告艺术设计等专业 | +-- | 604 | 管理工程系 | 连锁经营管理等专业 | +insert into Department values +(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 | 重庆市南岸区 | +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,'重庆市南岸区'); +-- 4、用SELECT语句查询Teacher表的所有记录。 +select * from Teacher; +``` + -- Gitee From c95d1bb728f15ae43bca14235884816a83d5e240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8F=AD=E9=98=B3=E4=B8=BD?= <2431466589@qq.com> Date: Fri, 24 Feb 2023 12:45:58 +0800 Subject: [PATCH 2/3] =?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 --- ...230224 select\350\257\255\345\217\245.txt" | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 "37 \346\217\255\351\230\263\344\270\275/20230224 select\350\257\255\345\217\245.txt" diff --git "a/37 \346\217\255\351\230\263\344\270\275/20230224 select\350\257\255\345\217\245.txt" "b/37 \346\217\255\351\230\263\344\270\275/20230224 select\350\257\255\345\217\245.txt" new file mode 100644 index 0000000..7424828 --- /dev/null +++ "b/37 \346\217\255\351\230\263\344\270\275/20230224 select\350\257\255\345\217\245.txt" @@ -0,0 +1,151 @@ +```mysql +-- ## 第1题:员工表 +CREATE database top charset utf8; +use top; +-- ```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 +-- ); +drop table if exists `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); +-- ``` + 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之间的员工信息。 +select salary from employee where salary between 12000 and 13000; +-- **要求2:**查询出姓“刘”的员工的工号,姓名,家庭住址。 +select id,name,addr from employee where name like '刘%'; +-- **要求3:**将“李四”的家庭住址改为“广东韶关” +update employee set addr='广东韶关' where name='李四'; +select * from employee; +-- **要求4:**查询出名字中带“小”的员工 +select * from employee where name like '%小%'; +-- **要求5:**查询出薪资高于11000的男员工信息 +select * from employee where sex='男' and salary>11000; +-- **要求6:**查询没有登记电话号码的员工 +select * from employee where tel is null; +-- **要求7:**查询薪资高于12000或者家是广东深圳、广州的男员工 +select * from employee where salary>12000 or (addr='广东深圳'and sex='男' or addr='广东广州'and sex='男'); +-- **要求8:**查询每个员工的年薪,显示“姓名、年薪” + select name,salary from employee ; +-- ```mysql +-- +-- ``` +-- +-- ## 第2题:国家信息表 +-- +-- countries_info表中存储了国家名称、所属大陆、面积、人口和 GDP 值。 +create database way charset utf8; +use way; +-- ```mysql +-- DROP TABLE IF EXISTS `countries_info`; +-- CREATE TABLE `countries_info`( +-- `name` VARCHAR(100), +-- `continent` VARCHAR(100), +-- `area` INT, +-- population INT, +-- gdp BIGINT +-- ); +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); +-- ``` +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:** 查询大国 的国家名称、人口和面积。 +select name,area,population from countries_info where area>=3000000 or population>=25000000; +-- 如果一个国家满足下述两个条件之一,则认为该国是 大国 : +-- +-- - 面积至少为 300万平方公里(即,3000000 km2) +-- +-- - 人口至少为 2500 万(即 25000000) +-- +-- **要求2:**查询属于亚洲的国家名称、所属大陆、面积、人口和 GDP 值 +select name,continent,area,population,gdp from countries_info where continent='Asia'; +-- **要求3:**查询国土面积不足1万平方公里且人口不走10万人的国家信息 +select * from countries_info where area<10000 and population <100000; +-- **要求4:**查询国家名字中包含“o“字母的国家信息 +select * from countries_info where name like '%o%'; +-- **要求5:**查询GDP值超过10000000000的国家信息 +select * from countries_info where gdp> 10000000000; +-- **要求6:**查询每个国家的人均贡献GDP值(GDP/人口总数)并显示为“国家名、人口、GDP值、人均贡献GDP值” +select name as 国家名, +population as 人口, +gdp as GDP值, +gdp / population as 人均贡献GDP值 + from countries_info; +-- **要求7:**查询人均贡献GDP值低于1000的国家信息。 +select * from countries_info where (gdp / population)<1000; +-- **要求8:**查询每个国家的人均国土面积(面积/人口总数)并显示为“国家名、面积、人口、人均国土面积值” +select name as 国家名, +population as 人口, +gdp as GDP值, +area / population as 人均国土面积值 + from countries_info; +``` + -- Gitee From 3b44dabbf3740b8c093e60a0db6c48134bf03958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8F=AD=E9=98=B3=E4=B8=BD?= <2431466589@qq.com> Date: Thu, 9 Mar 2023 11:46:18 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=AC=AC=E4=BA=94=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 --- ... \345\255\220\346\237\245\350\257\242.txt" | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 "37 \346\217\255\351\230\263\344\270\275/20230309 \345\255\220\346\237\245\350\257\242.txt" diff --git "a/37 \346\217\255\351\230\263\344\270\275/20230309 \345\255\220\346\237\245\350\257\242.txt" "b/37 \346\217\255\351\230\263\344\270\275/20230309 \345\255\220\346\237\245\350\257\242.txt" new file mode 100644 index 0000000..cdb9872 --- /dev/null +++ "b/37 \346\217\255\351\230\263\344\270\275/20230309 \345\255\220\346\237\245\350\257\242.txt" @@ -0,0 +1,79 @@ +```my +查询作业 +create database sonselect charset utf8; +use sonselect; +create table stuinfo( +stuNo varchar(10), +stuName varchar(4), +stuSex enum('男','女'), +stuAge int, +stuAddress varchar(4), +stuSeat INT +); +create table stuExam( +examNo int, +stuNo varchar(10), +writtenExam int, +labExam INT +); +create table stuMarks( +examNo int, +stuID varchar(10), +score int +); +insert into stuinfo values +('s2501','张秋利','男',20,'美国硅谷',1), +('s2502','李斯文','女',18,'湖北武汉',2), +('s2503','马文才','男',18,'湖南长沙',3), +('s2504','欧阳俊雄','女',21,'湖北武汉',4), +('s2505','梅超风','男',20,'湖北武汉',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 >(select AVG(stuAge) from stuinfo); +-- 2.查询出每个学生的学号,姓名,性别和选修课程的最高分(stuMarks) +select stuno,stuname,stusex,max(score) from stumarks a right join stuinfo b on a.stuid = b.stuno group by stuno,stuname,stusex; +-- 3.查询出每个学生的学号,姓名,性别和考试平均分(stuExam) +select stuinfo.stuNo,stuName,stuSex,avg(writtenExam+labExam)/2 考试平均分 from stuinfo left JOIN stuexam on stuinfo.stuNo=stuexam.stuNo GROUP BY stuinfo.stuNo,stuName,stuSex; +-- 4.查询性别是男并且年龄大于等于20的学生的信息(用两种方法实现:普通查询和子查询) +select * from stuinfo where stuSex='男' and stuage>=20; +select * from (select * from stuinfo where stuage>=20) a where stusex='男'; +-- 5.查询出年龄比所有男生年龄都大的女生的信息 +select * from stuinfo where stusex='女' AND stuage>ALL(select stuAge from stuinfo where stusex='男'); +-- 6.查询出所有选修课程都及格的学生的信息 (stuMarks) +select * from stuinfo a INNER JOIN stumarks b on a.stuNo = b.stuID where a.stuNo != (select stuid from stumarks where score<60); +-- 7.查询出参加考试的学生的信息(用表连接,in二种方法做)(stuMarks) +SELECT * FROM stuinfo a inner join stumarks b on a.stuNo = b.stuID; +select * from stuinfo a inner join (select DISTINCT stuid from stumarks) b on a.stuNo = b.stuid; +select * FROM stuinfo where stuno in (select DISTINCT stuid from stumarks); +-- 8.查询出没有参加考试的学生的信息(用表连接,in二种方法做)(stuMarks) +SELECT * from stuinfo a left join stumarks b on a.stuNo = b.stuID where score is null; +select * from stuinfo where stuno not in (SELECT DISTINCT stuid FROM stuMarks); +-- 9.将有一门成绩成绩大于90分的学生的基本信息查询出来(stuMarks) +select * from stuinfo a left join stumarks b on a.stuNo = b.stuID where score>90; +select * from stuinfo where stuno in (select stuid from stumarks where score>90); +-- 10.查询出平均成绩在80分以上的学生的基本信息(stuExam) +select * from stuinfo where stuno = (select stuno from stuexam where (writtenExam+labExam)/2>80); +-- 11.查询出某同学所有考试成绩比“张秋利”同学所有分数都高的学生基本信息(stuExam) +-- 12.查询出某同学所有考试成绩只需要比“张秋利”同学某个分数高的学生基本信息(stuExam) +-- 13.查询班上比所有男生年龄都要大的女生的信息 +select * from stuinfo where stuSex='女' and stuAge >ALL(select stuAge from stuinfo where stusex='男'); +-- 14.查询出只是比某个男生年龄大的女生的信息 +select * from stuinfo where stuSex='女' AND stuAge >any(select stuage from stuinfo where stusex='男'); +select * from stuinfo where stuSex='女' AND stuAge >(select MIN(stuAge) from stuinfo where stusex='男'); +``` + -- Gitee