From af3b607e4086023eaaae004591ac2c1bbb82cf40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B1=BD=E5=A2=83?= <1537282342@qq.com> Date: Sun, 5 Mar 2023 12:49:26 +0800 Subject: [PATCH 1/2] 1 --- ...7\346\234\254\346\226\207\346\241\243.txt" | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 "28 \351\273\204\346\242\223\345\242\203/20230305/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" diff --git "a/28 \351\273\204\346\242\223\345\242\203/20230305/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/28 \351\273\204\346\242\223\345\242\203/20230305/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" new file mode 100644 index 0000000..4937b24 --- /dev/null +++ "b/28 \351\273\204\346\242\223\345\242\203/20230305/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" @@ -0,0 +1,138 @@ +create database test charset utf8; +use test; +create table student( +Sno varchar(20) primary key comment'学号', +Sname varchar(20)not null comment'学生姓名', +Ssex varchar(20)not null comment'学生性别', +Sbirthday datetime comment'学生出生年月', +Class varchar(20) comment'学生所在班级' +); +create table course( +Cno varchar(20) primary key comment'课程号', +Cname varchar(20)not null comment'课程名称', +Tno varchar(20)not null comment'教工编号', +foreign key (Tno) references Teacher(Tno) +); +create table score( +Sno varchar(20)not null comment'学号', +Cno varchar(20)not null comment'课程号', +Degree decimal(4,1) comment'成绩', +primary key (Sno,Cno), +foreign key (Sno) references Student(Sno), +foreign key (Cno) references Course(Cno) +); +create table teacher( +Tno varchar(20)primary key comment'教工编号', +Tname varchar(20)not null comment'教工姓名', +Tsex varchar(20)not null comment'教工性别', +Tbirthday datetime comment'教工出生年月', +Prof varchar(20) comment'职称', +Depart varchar(20)not null comment'教工所在部门' +); +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','825'), +('105','3-245','804'), +('109','3-245','856'), +('103','3-105','831'), +('105','3-105','825'), +('109','3-105','804'), +('101','3-105','856'), +('107','3-105','825'), +('108','3-105','804'), +('101','6-166','856'), +('107','6-166','825'), +('108','6-166','804'); +insert into teacher values +('804','李诚','男','1958-12-2','副教授','计算机系'), +('856','张旭','男','1969-3-12','讲师','电子工程系'), +('825','王萍','女','1972-5-5','讲师','计算机系'), +('831','刘冰','女','1977-8-14','讲师','电子工程系'); +-- 1,查询所有学生,都学了哪些课程,要显示学生信息和课程信息 + +select st.Sname,co.Cname from student st,course co,score sc where st.Sno=sc.Sno and co.Cno=sc.Cno; +-- 2,查询没有学生的教师的所有信息 + +select * from teacher te left join course co on te.Tno=co.Tno left join score sc on co.Cno=sc.Cno where sc.Cno is null; + 查询Score表中的最高分的学生学号和课程号。 + +select Sno,Cno from score where Degree=(select max(Degree) from score); + 查询所有学生的Sname、Cno和Degree列。 + +select st.Sname,sc.Cno,sc.Degree from student st ,score sc where st.sno=sc.sno; + 查询所有学生的Sno、Cname和Degree列。 + +select st.Sno,st.Sname,sc.Degree from student st ,score sc where st.sno=sc.sno; + 查询所有学生的Sname、Cname和Degree列。 + +select st.Sname,co.Cname,sc.Degree from student st ,course co ,score sc where st.sno=sc.sno and co.Cno=sc.Cno; + 查询“95033”班学生的平均分。 + +select avg(sc.Degree) from student st, score sc where st.Sno=sc.Sno and Class='95033'; + 查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。 + +select * from score where Degree>(select Degree from score where Sno='109'and Cno='3-105') and Cno='3-105'; + 查询score中选学多门课程的同学中分数为非最高分成绩的记录。 + +select * from score where Degree not in (select max(Degree) from score group by Cno); + 查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。 + +select * from score where Degree>(select Degree from score where Sno='109' and Cno='3-105'); + 查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。 + +select Sno,Sname,Sbirthday from student where year(Sbirthday)=(select year(Sbirthday) from student where Sno='108') and Sno!='108'; + 查询“张旭“教师任课的学生成绩。 + +select Degree from teacher te,score sc,course co where te.Tno= co.Tno and co.Cno=sc.Cno and tname='张旭'; + 查询选修某课程的同学人数多于5人的教师姓名。 + +select tname from course co,teacher te where co.Tno=te.Tno and Cno=(select Cno from score group by Cno having count(*)>5); + 查询出“计算机系“教师所教课程的成绩表。 + +select sc.* from course co, score sc where co.Cno = sc.Cno and co.Tno in(select Tno from teacher where Depart='计算机系'); + 查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。 + +select Tname,Prof from teacher where Prof not in (select Prof from teacher where Depart='计算机系') +union all +select Tname,Prof from teacher where Prof not in (select Prof from teacher where Depart='电子工程系'); + 查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。 + +select Cno,Sno,Degree from score where Cno='3-105' and Degree>all(select Degree from score where Cno='3-245') order by Degree desc; + 查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degree. + +select * from score where Cno='3-105' and Degree>all(select Degree from score where Cno='3-245'); + 查询成绩比该课程平均成绩低的同学的成绩表。 + +select * from score a where a.Degree<(select avg(Degree) from score b where a.Cno=b.Cno); + 查询所有任课教师的Tname和Depart. + +select Tname,Depart from teacher; +查询所有未讲课的教师的Tname和Depart. + +select te.tname,te.Depart from teacher te left join course co on te.Tno = co.Tno left join score sc on co.Cno = sc.Cno where sc.Sno is null ; + 查询“男”教师及其所上的课程。 + +select * from teacher te,course co where te.tno=co.Tno and Tsex='男'; + 查询最高分同学的Sno、Cno和Degree列。 + +select sno,Cno,Degree from score where Cno in(select Cno from score group by Cno) and Degree in (select max(Degree) from score group by Cno); + 查询和“李军”同性别的所有同学的Sname. + +select Sname from student where Ssex=(select Ssex from student where Sname='李军'); + 查询和“李军”同性别并同班的同学Sname. + +select Sname from student where Ssex=(select Ssex from student where Sname='李军') and Class=(select class from student where Sname='李军'); + 查询所有选修“计算机导论”课程的“男”同学的成绩表。 + +select * from student st , score sc ,course co where st.Sno=sc.Sno and co.Cno=sc.Cno and st.Ssex='男' and co.Cname='计算机导论'; \ No newline at end of file -- Gitee From ccac3487e0cab0ea219c8b4fbb98e61cde852c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B1=BD=E5=A2=83?= <1537282342@qq.com> Date: Tue, 7 Mar 2023 22:56:48 +0800 Subject: [PATCH 2/2] 1 --- ...7\346\234\254\346\226\207\346\241\243.txt" | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 "28 \351\273\204\346\242\223\345\242\203/20230306/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" diff --git "a/28 \351\273\204\346\242\223\345\242\203/20230306/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/28 \351\273\204\346\242\223\345\242\203/20230306/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" new file mode 100644 index 0000000..90f23ad --- /dev/null +++ "b/28 \351\273\204\346\242\223\345\242\203/20230306/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" @@ -0,0 +1,92 @@ +create database class10 charset utf8; +use class10; +create table stuinfo( +stuNO varchar(10), +stuName varchar(16), +stuSex varchar(2), +stuAge varchar(2), +stuAddress varchar(16), +stuSeat varchar(1) +); +select * from stuinfo; + +insert into stuinfo VALUES +('s2501','寮犵鍒','鐢',20,'缇庡浗纭呰胺',1), +('s2502','鏉庢柉鏂','濂',18,'婀栧寳姝︽眽',2), +('s2503','椹枃鎵','鐢',22,'婀栧寳闀挎矙',3), +('s2504','娆ч槼淇婇泟','濂',21,'婀栧寳姝︽眽',4), +('s2505','姊呰秴椋','鐢',20,'婀栧寳姝︽眽',5), +('s2506','闄堟棆椋','鐢',19,'缇庡浗纭呰胺',6); +create table stuEam ( +examNO varchar(10), +stuNO varchar(10), +writtenExam varchar(4), +labExam varchar(4) +); +insert into stuEam 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); +create table stuMarks( +examNo varchar(1), +stuID varchar(10), +score varchar(2) +); +insert into stuMarks VALUES +(1,'s2501',88), +(2,'s2502',92), +(3,'s2503',53), +(4,'s2504',60), +(5,'s2505',99), +(6,'s2506',82); +select * from stuMarks; +-- 鍦ㄥ鍥剧殑鏁版嵁琛ㄤ笂瀹屾垚浠ヤ笅棰樼洰 +-- +-- 1.鏌ヨ鍑哄勾榫勬瘮鐝笂骞冲潎骞撮緞澶х殑瀛︾敓鐨勪俊鎭 +select * from stuinfo where stuAge > (select avg(stuAge) from stuinfo); +-- +-- 2.鏌ヨ鍑烘瘡涓鐢熺殑瀛﹀彿锛屽鍚嶏紝鎬у埆鍜岄変慨璇剧▼鐨勬渶楂樺垎锛坰tuMarks锛 +select stuNO,stuName,stuSex,score from stuinfo info left join stuMarks mar on info.stuNO = mar.stuID; +-- +-- 3.鏌ヨ鍑烘瘡涓鐢熺殑瀛﹀彿锛屽鍚嶏紝鎬у埆鍜岃冭瘯骞冲潎鍒嗭紙stuExam锛 +select info.stuNO,stuName,stuSex,(select (writtenExam + labExam)/2) from stuinfo info left JOIN stuEam Ex on info.stuNO = Ex.stuNO; +-- +-- 4.鏌ヨ鎬у埆鏄敺骞朵笖骞撮緞澶т簬绛変簬20鐨勫鐢熺殑淇℃伅(鐢ㄤ袱绉嶆柟娉曞疄鐜帮細鏅氭煡璇㈠拰瀛愭煡璇) +select * from stuinfo where stuSex = '鐢' and stuAge >= 20; +select * from (select * from stuinfo where stuSex = '鐢' and stuAge >= 20) as biemin1; +-- 5.鏌ヨ鍑哄勾榫勬瘮鎵鏈夌敺鐢熷勾榫勯兘澶х殑濂崇敓鐨勪俊鎭 +update stuinfo set stuAge = 25 where stuNO = 's2504'; +select * from stuinfo where stuAge > (select max(select stuAge from stuinfo where stuSex = '鐢') as biemin2 from stuinfo) and stuSex = '濂';-- 鏈夐棶棰 +select * from stuinfo where stuAge > (select max(stuAge) from stuinfo where stuSex = '鐢') and stuSex = '濂'; +select * from stuinfo; + +-- +-- 6.鏌ヨ鍑烘墍鏈夐変慨璇剧▼閮藉強鏍肩殑瀛︾敓鐨勪俊鎭 锛坰tuMarks锛 +select * from stuMarks where score >= 60; +-- +-- 7.鏌ヨ鍑哄弬鍔犺冭瘯鐨勫鐢熺殑淇℃伅锛堢敤琛ㄨ繛鎺ワ紝in浜岀鏂规硶鍋氾級锛坰tuMarks锛 +-- +select * from +-- 8.鏌ヨ鍑烘病鏈夊弬鍔犺冭瘯鐨勫鐢熺殑淇℃伅锛堢敤琛ㄨ繛鎺ワ紝in浜岀鏂规硶鍋氾級锛坰tuMarks锛 +select *from +-- +-- 9.灏嗘湁涓闂ㄦ垚缁╂垚缁╁ぇ浜90鍒嗙殑瀛︾敓鐨勫熀鏈俊鎭煡璇㈠嚭鏉ワ紙stuMarks锛 +select * from stuinfo left join stuMarks on stuID=stuNO where score > 90; +-- +-- 10.鏌ヨ鍑哄钩鍧囨垚缁╁湪80鍒嗕互涓婄殑瀛︾敓鐨勫熀鏈俊鎭紙stuMarks锛 +-- +select * from stuinfo left join stuMarks on stuID = stuNO where (select avg())>80; +-- 11.鏌ヨ鍑烘煇鍚屽鎵鏈夎冭瘯鎴愮哗姣斺滃紶绉嬪埄鈥濆悓瀛︽墍鏈夊垎鏁伴兘楂樼殑瀛︾敓鍩烘湰淇℃伅锛坰tuMarks锛 +select * from stuinfo having ()<(select ) +-- +-- 12.鏌ヨ鍑烘煇鍚屽鎵鏈夎冭瘯鎴愮哗鍙渶瑕佹瘮鈥滃紶绉嬪埄鈥濆悓瀛︽煇涓垎鏁伴珮鐨勫鐢熷熀鏈俊鎭紙stuMarks锛 +select * from stuinfo left join stuMarks on stuID = stuNO where score > (select score from stuinfo left join stuMarks on stuID = stuNO where stuName = '寮犵鍒') +-- +-- 13.鏌ヨ鐝笂姣旀墍鏈夌敺鐢熷勾榫勯兘瑕佸ぇ鐨勫コ鐢熺殑淇℃伅 +select * from stuinfo where stuAge > (select max(stuAge) from stuinfo where stuSex = '鐢') having stuSex = '濂'; +-- +-- 14.鏌ヨ鍑哄彧鏄瘮鏌愪釜鐢风敓骞撮緞澶х殑濂崇敓鐨勪俊鎭 +select \ No newline at end of file -- Gitee