From 72a4fd106def7a0c6f75d069c4f77af3c1ddf897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E4=BB=A4=E9=B9=8F?= <1963831974@qq.com> Date: Wed, 1 Mar 2023 22:08:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...06\347\273\204\346\237\245\350\257\242.md" | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 "12 \350\213\217\344\273\244\351\271\217/20230227\344\275\234\344\270\232 \350\201\232\345\220\210\345\207\275\346\225\260\345\210\206\347\273\204\346\237\245\350\257\242.md" diff --git "a/12 \350\213\217\344\273\244\351\271\217/20230227\344\275\234\344\270\232 \350\201\232\345\220\210\345\207\275\346\225\260\345\210\206\347\273\204\346\237\245\350\257\242.md" "b/12 \350\213\217\344\273\244\351\271\217/20230227\344\275\234\344\270\232 \350\201\232\345\220\210\345\207\275\346\225\260\345\210\206\347\273\204\346\237\245\350\257\242.md" new file mode 100644 index 0000000..da6271f --- /dev/null +++ "b/12 \350\213\217\344\273\244\351\271\217/20230227\344\275\234\344\270\232 \350\201\232\345\220\210\345\207\275\346\225\260\345\210\206\347\273\204\346\237\245\350\257\242.md" @@ -0,0 +1,220 @@ +```mysql +create database class charset utf8; +use class; +CREATE TABLE `student` +( + `Sno` varchar(20) NOT NULL, + `Sname` varchar(20) NOT NULL, + `Ssex` varchar(20) NOT NULL, + `Sbirthday` datetime DEFAULT NULL, + `Class` varchar(20) DEFAULT NULL, + PRIMARY KEY (`Sno`) +); +CREATE TABLE `course` +( + `Cno` varchar(20) NOT NULL, + `Cname` varchar(20) NOT NULL, + `Tno` varchar(20) NOT NULL, + PRIMARY KEY (`Cno`), + KEY `tno` (`Tno`), + CONSTRAINT `tno` FOREIGN KEY (`Tno`) REFERENCES `teacher` (`Tno`) +); +CREATE TABLE `score` +( + `Sno` varchar(20) NOT NULL, + `Cno` varchar(20) NOT NULL, + `Degree` decimal(4, 1) DEFAULT NULL, + PRIMARY KEY (`Sno`, `Cno`), + KEY `cno` (`Cno`), + CONSTRAINT `cno` FOREIGN KEY (`Cno`) REFERENCES `course` (`Cno`), + CONSTRAINT `sno` FOREIGN KEY (`Sno`) REFERENCES `student` (`Sno`) +); +CREATE TABLE `teacher` +( + `Tno` varchar(20) NOT NULL, + `Tname` varchar(20) NOT NULL, + `Tsex` varchar(20) NOT NULL, + `Tbirthday` datetime DEFAULT NULL, + `Prof` varchar(20) DEFAULT NULL, + `Depart` varchar(20) NOT NULL, + PRIMARY KEY (`Tno`) +); +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', '助教', '电子工程系'); +# 1,查询所有学生,都学了哪些课程,要显示学生信息和课程信息 +select * +from student + inner join score on student.Sno = score.Sno + inner join course on score.Cno = course.Cno; +# 2,查询没有学生的教师的所有信息 +select teacher.* +from teacher + left join course on teacher.Tno = course.Tno + left join score on course.Cno = score.Cno +where + Sno is null; +# ① 查询Score表中的最高分的学生学号和课程号。 +select s.Sno, Sname,cno +from student s + inner join score on s.Sno = score.Sno +where + Degree = (select max(Degree) from score); +# ② 查询所有学生的Sname、Cno和Degree列。 +select Sname, score.Cno, Degree +from student, + score +where student.Sno = score.Sno; +# ③ 查询所有学生的Sno、Cname和Degree列。 +select Sno, Cname, Degree +from course, + score +where course.Cno = score.Cno; +# ④ 查询所有学生的Sname、Cname和Degree列。 +select Sname, Cname, Degree +from student, + course, + score +where student.Sno = score.Sno + and course.Cno = score.Cno; +# ⑤ 查询“95033”班学生的平均分。 +select class,avg(Degree) from score s,student s2 where s.Sno = s2.Sno and class=95033; +# ⑥ 查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。 +select student.* +from student + inner join score on student.Sno = score.Sno +where Cno = '3-105' + and Degree > (student.Sno = 109); +# ⑦ 查询score中选学多门课程的同学中分数为非最高分成绩的记录。 +select max(Degree) +from score +group by Cno; +select * +from score +where Degree not in (select max(Degree) from score group by Cno); +# ⑧ 查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。 +select * +from score +where cno = '3-105' + and Degree > (sno = 109); +# ⑨ 查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。 +select Sno, Sname, Sbirthday +from student +where Sbirthday = (sno = 108); +# ⑩ 查询“张旭“教师任课的学生成绩。 +select Sno, Degree +from score s + inner join course c on c.cno = s.cno + inner join teacher t on c.Tno = t.Tno +where tname = '张旭'; +# 11 查询选修某课程的同学人数多于5人的教师姓名。 +select tname, count(c.Tno) +from score s + inner join course c on s.Cno = c.Cno + inner join teacher t on c.Tno = t.Tno +group by tname +having count(c.tno) > 5; +# 12 查询出“计算机系“教师所教课程的成绩表。 +select Depart, tname, sno, s.Cno, Degree +from teacher t + inner join course c on t.Tno = c.Tno + inner join score s on c.Cno = s.Cno +where Depart = '计算机系'; +# 13 查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。 +select Tname, Prof, Depart +from teacher +where Depart = '计算机系' + or Depart = '电子工程系'; +# 14 查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。 +select cno, st.Sno, degree +from score s + inner join student st on s.Sno = st.Sno +where cno = '3-105' + and Degree > (cno = '3-245') +order by degree desc +; +# 15 查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degree. +select s.Cno, Sno, Degree +from score s + inner join course c on s.Cno = c.Cno +where c.Cno = '3-105' + and Degree > (c.Cno = '3-245'); +# 16 查询成绩比该课程平均成绩低的同学的成绩表。 +select avg(Degree) +from score +group by Cno; +select * +from score +where Degree < (select avg(Degree) from score); +# 17 查询所有任课教师的Tname和Depart. +select Tname, depart +from teacher; +# 18 查询所有未讲课的教师的Tname和Depart. +select Tname, Depart +from teacher t + left join course c on t.Tno = c.Tno + left join score s on s.Cno = c.Cno +where Sno is null; +# 19 查询“男”教师及其所上的课程。 +select c.* +from course c + inner join teacher t on c.Tno = t.Tno +where Tsex = '男'; +# 20 查询最高分同学的Sno、Cno和Degree列。 +select Sno, Cno, max(Degree) +from score; +# 21 查询和“李军”同性别的所有同学的Sname. +select Ssex +from student +where Sname = '李军'; +select Sname +from student +where Ssex = (select Ssex from student where Sname = '李军'); +# 22 查询和“李军”同性别并同班的同学Sname. +select class +from student +where Sname = '李军'; +select Sname +from student +where Ssex = (select Ssex from student where Sname = '李军') +and + class not in (select class +from student +where Sname = '李军'); +# 23 查询所有选修“计算机导论”课程的“男”同学的成绩表。 +select s.* from score s +inner join student s2 on s.Sno = s2.Sno +inner join course c on s.Cno = c.Cno +where + Cname = '计算机导论' +and + Ssex='男'; +``` + -- Gitee From 43421aaa47cde84d83bd5fa2aacb8ebcbb3afe86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E4=BB=A4=E9=B9=8F?= <1963831974@qq.com> Date: Tue, 7 Mar 2023 22:23:40 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20230306\344\275\234\344\270\232.md" | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 "12 \350\213\217\344\273\244\351\271\217/20230306\344\275\234\344\270\232.md" diff --git "a/12 \350\213\217\344\273\244\351\271\217/20230306\344\275\234\344\270\232.md" "b/12 \350\213\217\344\273\244\351\271\217/20230306\344\275\234\344\270\232.md" new file mode 100644 index 0000000..7fa8d51 --- /dev/null +++ "b/12 \350\213\217\344\273\244\351\271\217/20230306\344\275\234\344\270\232.md" @@ -0,0 +1,136 @@ +```mysql +create database works charset utf8; +use works; +create table stuinfo +( + stuNo varchar(10) primary key, + stuName varchar(5) not null, + stuSex enum ('男','女') not null, + stuAge int not null, + stuAddress varchar(5) not null, + stuSeat int not null +); +CREATE TABLE stuexam +( + `examNO` int(11) NOT NULL, + `stuNO` varchar(5) NOT NULL, + `writtenExam` int(11) NOT NULL, + `labExam` int(11) NOT NULL, + PRIMARY KEY (`examNO`), + KEY `stuNO` (`stuNO`), + CONSTRAINT `stuNO` FOREIGN KEY (`stuNO`) REFERENCES `stuinfo` (`stuNo`) +); +CREATE TABLE stumarks +( + `examNO` int(11) NOT NULL, + `stuID` varchar(5) NOT NULL, + `score` int(11) NOT NULL, + KEY `examNO` (`examNO`), + KEY `stuid` (`stuID`), + CONSTRAINT `examNO` FOREIGN KEY (`examNO`) REFERENCES `stuexam` (`examNO`), + CONSTRAINT `stuid` FOREIGN KEY (`stuID`) REFERENCES `stuinfo` (`stuNo`) +); +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 stuinfo inf + left join stumarks ma on inf.stuNo = ma.stuID +group by stuNo; +# 3.查询出每个学生的学号,姓名,性别和考试平均分(stuExam) +select inf.stuNo, stuName, stuSex, (writtenExam+labExam)/2 num +from stuinfo inf + left join stuexam ex on inf.stuNo = ex.stuNO +group by stuNo; +# 4.查询性别是男并且年龄大于等于20的学生的信息(用两种方法实现:普通查询和子查询) +select * +from stuinfo +where stuSex = '男' + and stuAge >= 20; +select * +from stuinfo +where stuAge in (select stuAge from stuinfo where stuage >= 20) + and stuSex in (select stuSex from stuinfo where stuSex = '男'); +# 5.查询出年龄比所有男生年龄都大的女生的信息 +select * +from stuinfo +where stuAge > (select max(stuAge) from stuinfo where stuSex = '男'); +# 6.查询出所有选修课程都及格的学生的信息 (stuMarks) +select inf.* +from stuinfo inf,(select stuID from stumarks group by stuID having min(score)>=60) num +where inf.stuNo = num.stuID; +# 7.查询出参加考试的学生的信息(用表连接,in二种方法做)(stuMarks) +select inf.* +from stuinfo inf + left join stumarks s on inf.stuNo = s.stuID +where score is not null; +# 8.查询出没有参加考试的学生的信息(用表连接,in二种方法做)(stuMarks) +select inf.* +from stuinfo inf + left join stumarks s on inf.stuNo = s.stuID +where score is null; +# 9.将有一门成绩成绩大于90分的学生的基本信息查询出来(stuMarks) +select inf.* +from stuinfo inf + inner join stumarks s on inf.stuNo = s.stuID +where score in (select score from stumarks where score > 90); +# 10.查询出平均成绩在80分以上的学生的基本信息(stuMarks) +select s.*, avg(score) num +from stumarks ma + inner join stuinfo s on ma.stuID = s.stuNo +group by ma.stuID +having num > 80; +# 11.查询出某同学所有考试成绩比“张秋利”同学所有分数都高的学生基本信息(stuMarks) +select * +from (select *, max(score) num + from stuinfo inf + inner join stumarks ma on inf.stuNo = ma.stuID + group by stuID) maxsc +where num > (select max(score) from stumarks where stuID = 's2501'); +# 12.查询出某同学所有考试成绩只需要比“张秋利”同学某个分数高的学生基本信息(stuMarks) +select s2.* +from stumarks + inner join stuinfo s2 on stumarks.stuID = s2.stuNo +where score > (select min(score) + from stumarks + inner join stuinfo s on stumarks.stuID = s.stuNo + where stuName = '张秋利') + and stuName != '张秋利' +group by stuNo; +# 13.查询班上比所有男生年龄都要大的女生的信息 +select * +from stuinfo +where (stuage > (select max(stuAge) from stuinfo where stuSex = '男')) + and stuSex = '女'; +# 14.查询出只是比某个男生年龄大的女生的信息 +select * +from stuinfo +where (stuage > (select min(stuAge) from stuinfo where stuSex = '男')) + and stuSex = '女'; +``` + -- Gitee From d28dd241a9a92711b71313a8a3dbb6e5ce746b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E4=BB=A4=E9=B9=8F?= <1963831974@qq.com> Date: Thu, 9 Mar 2023 10:45:01 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20230308\344\275\234\344\270\232.md" | 202 ++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 "12 \350\213\217\344\273\244\351\271\217/20230308\344\275\234\344\270\232.md" diff --git "a/12 \350\213\217\344\273\244\351\271\217/20230308\344\275\234\344\270\232.md" "b/12 \350\213\217\344\273\244\351\271\217/20230308\344\275\234\344\270\232.md" new file mode 100644 index 0000000..5521053 --- /dev/null +++ "b/12 \350\213\217\344\273\244\351\271\217/20230308\344\275\234\344\270\232.md" @@ -0,0 +1,202 @@ +```mysql +# **场景**: +# +# 你在一个软件公司上班,今天公司接一个新业务。要用MySQL给一个小说网站设计一个数据库。 +# +# **数据库名**:xiaoshuo +create database xiaoshuo charset utf8; +use xiaoshuo; +# 该数据库里有四张表:作家信息表 ( author )、作家等级信息表 ( vip )、小说作品信息表 ( story )、小说作品类型表 ( type ) +# +# ### 1、相关表结构 +# +# 1. 作家信息表 ( author ) (4分) +# +# | 字段名称 | 数据类型 | 说明及要求 | +# | ----------- | ----------- | --------------------------------- | +# | author_id | int | 作家编号,主键 | +# | author_name | varchar(20) | 作家姓名、非空、不能重复 | +# | credits | int | 积分 | +# | vip_id | varchar(20) | 等级编号,非空、外键关联等级信息表 | +create table author( + author_id int primary key , + author_name varchar(20) not null unique, + credits int, + vip_id varchar(20), + foreign key (vip_id) references vip(vip_id) +); +# 2. 作家等级信息表 ( vip ) (3分) +# +# | 字段名称 | 数据类型 | 说明及要求 | +# | -------- | ----------- | ------------------------ | +# | vip_id | varchar(20) | 等级编号,主键 | +# | vip_name | varchar(20) | 等级名称,非空,不能重复 | +create table vip( + vip_id varchar(20) primary key , + vip_name varchar(20) not null unique +); +# +# 3. 小说作品信息表 ( story )(4分) +# +# | 字段名称 | 数据类型 | 说明及要求 | +# | ------------ | ----------- | ----------------------------- | +# | story_id | int | 作品编号,主键,自增 | +# | author_id | int | 作家编号,外键,关联作家信息表 | +# | type_id | varchar(20) | 类型编号,外键,关键作品类型表 | +# | story_name | varchar(50) | 作品名称 | +# | views_number | int | 浏览量 | +create table story( + story_id int primary key auto_increment, + author_id int, + type_id varchar(20), + story_name varchar(50), + views_number int, + foreign key (author_id) references author(author_id), + foreign key (type_id) references type(type_id) +); +# 4. 小说作品类型表 ( type )(2分) +# +# +# | 字段名称 | 数据类型 | 说明及要求 | +# | --------- | ----------- | ------------------------ | +# | type_id | varchar(20) | 类型编号,主键 | +# | type_name | varchar(20) | 类型名称,非空,不能重复 | +create table type( + type_id varchar(20) primary key , + type_name varchar(20) not null unique +); +# ### 2、对应的表数据 +# +# 1. 作家信息表 (4分) +# +# +# | 作家编号 | 作家名称 | 积分 | 等级编号 | +# | :------: | :------: | :--: | :------: | +# | 1001 | 朱逸群 | 600 | VIP01 | +# | 1002 | 范建 | 8510 | VIP04 | +# | 1003 | 史珍香 | 981 | VIP02 | +# | 1004 | 范统 | 2364 | VIP02 | +# | 1005 | 杜子腾 | 257 | VIP01 | +# | 1006 | 刘产 | 678 | VIP02 | +# | 1007 | 杜琦燕 | 438 | VIP03 | +insert into author values(1001,'朱逸群',600,'VIP01'), + (1002,'范建',8510,'VIP04'), + (1003,'史珍香',981,'VIP02'), + (1004,'范统',2364,'VIP02'), + (1005,'杜子腾',257,'VIP01'), + (1006,'刘产',678,'VIP02'), + (1007,'杜琦燕',438,'VIP03'); +# 2. 等级信息表(2分) +# +# | 等级编号 | 等级名称 | +# | :------: | :------: | +# | VIP01 | 青铜作家 | +# | VIP02 | 白银作家 | +# | VIP03 | 黄金作家 | +# | VIP04 | 钻石作家 | +insert into vip values('VIP01','青铜作家'), + ('VIP02','白银作家'), + ('VIP03','黄金作家'), + ('VIP04','钻石作家'); +# 3. 小说作品信息表(5分) +# +# | 作品编号 | 作家编号 | 类型编号 | 作品名称 | 订阅数 | +# | :------: | :------: | :------: | :----------------------: | :----: | +# | 1 | 1002 | L03 | 母猪产后与护理师的二三事 | 6541 | +# | 2 | 1005 | L04 | 拖拉机大战蜘蛛侠 | 563 | +# | 3 | 1003 | L01 | 这只小龙虾不正经 | 8754 | +# | 4 | 1006 | L04 | 一个爹爹三个娃 | 36354 | +# | 5 | 1006 | L01 | 皇上滚开本宫只劫财 | 3674 | +# | 6 | 1005 | L05 | 给长城贴瓷砖的小太监 | 6541 | +# | 7 | 1003 | L03 | 不科学御兽 | 1257 | +# | 8 | 1005 | L01 | 镜面管理局 | 3216 | +# | 9 | 1004 | L02 | 关于我成为灭魂师之后 | 1147 | +# | 10 | 1004 | L05 | 公子别秀 | 2078 | +insert into story values(null,1002,'L03','母猪产后与护理师的二三事',6541), + (null,1005,'L04','拖拉机大战蜘蛛侠',563), + (null,1003,'L01','这只小龙虾不正经',8757), + (null,1006,'L04','一个爹爹三个娃',36354), + (null,1006,'L01','皇上滚开本宫只劫财',3674), + (null,1005,'L05','给长城贴瓷砖的小太监',6541), + (null,1003,'L03','不科学御兽',1257), + (null,1005,'L01','镜面管理局',3216), + (null,1004,'L02','关于我成为灭魂师之后',1147), + (null,1004,'L05','公子别秀',2078); +# 4. 作品类型(3分) +# +# | 类型编号 | 类型名称 | +# | :------: | :------: | +# | L01 | 玄幻 | +# | L02 | 奇幻 | +# | L03 | 武侠 | +# | L04 | 仙侠 | +# | L05 | 都市 | +# +insert into type values('L01','玄幻'), + ('L02','奇幻'), + ('L03','武侠'), + ('L04','仙侠'), + ('L05','都市'); +# ### 3、题目 +# +# > 所有题目要求使用SQL语句完成 +# +# 1. 根据前面提供的表结构和表数据,创建数据库并分别创建这张四张表;并插入相关数据。(提醒:外键请注意建表顺序和插入数据的顺序) (30分) +# +# 2. 将story 表中的story_name字段类型改成varchar(40) 。(2分) +alter table story modify story_name varchar(40); +# 3. 在author表中增加一个性别字段 字段名:author_sex,类型: char(10),要求默认值为'男'。 (3分) +alter table author add author_sex char(10) default '男'; +# 4. 将作家编号为1005、1007的作家性别改为'女' 。(2分) +update author set author_sex='女' where author_id=1005 and author_id=1007; +# 5. 作家杜子腾,写了一篇名为《拜登夸我很帅》的都市小说,有854个浏览量,请将这条信息插入到story表。(3分) +insert into story values(null,1005,'L05','拜登夸我很帅',854); +# 6. 《拖拉机大战蜘蛛侠》这篇小说,浏览量涨了100,请更新story表中的相关数据。(2分) +update story set views_number=views_number+100 where story_name='拖拉机大战蜘蛛侠'; +# 7. 请删除story表的中《皇上滚开本宫只劫财》这篇小说相关数据。(2分) +delete from story where story_name='皇上滚开本宫只劫财'; +# 8. 查询 浏览量大于 8000的小说的作者编号和小说作品名称。(2分) +select * from story where views_number>8000; +# 9. 查询积分大于1000 并且会员等级高于vip03的作家所有信息。(3分) +select * from author where credits>1000 and vip_id in('vip03','vip04'); +# 10. 查询姓名以杜字开头的作家的姓名,积分和等级编号。(3分) +select * from author where author_name like ('杜%'); +# 11. 查询积分在100、1000之间的作家信息,以积分降序排列。 (3分) +select * from author where 1002); +# 15. 查询所有小说中浏览量最少的书的作品编号、作品名称和类型编号、浏览量。(4分) +select a.author_id,author_name,type_id,views_number +from author a +inner join story s on a.author_id = s.author_id +where views_number=(select min(views_number) from story); +# 16. 查询积分比刘产高的作者所有信息。(5分) +select * from author + where + credits>(select credits from author where author_name='刘产'); +# 17. 查询出哪些白银作家是没有写小说的,显示这些作家的姓名、等级名称。(8分) +select a.author_name,a.vip_id from story s +right join author a on s.author_id = a.author_id +where vip_id = +(select vip_id from vip where vip_name='白银作家') +and story_id is null; +# 18. 找出写过作品浏览量大于5000的作家的所有作品中浏览量不到1000的作品信息(8分) +select * from story where +views_number<1000 and +author_id in (select author_id from story where views_number>5000); +# 19. 查询所有小说的小说编号、小说名称、浏览量、分类名称、作者姓名、作者积分、作者等级名称,结果字段要用中文别名,并按浏览量降序排列,如果浏览量一样的,再按积分降序排列。(10分) +select story_id 小说编号, story_name 小说名称,views_number 浏览量, type_id 分类名称, + author_name 作者姓名,credits 作者积分, vip_name 作者等级名称 from story,author,vip +where story.author_id=author.author_id and author.vip_id=vip.vip_id +order by views_number desc ,credits desc ; +``` + -- Gitee