mysql数据库⾯试题带答案(⼆)
1题:
根据3题的表完成下列操作
1.查询学⽣选课表中的全部数据
select * from sc;
2.查询全体学⽣的姓名、学号和所在系。
select sname,sno,sdept from student;
3.查询全体学⽣的姓名及其出⽣年份。
select sname,2020-sage 出⽣年份 from student;
4.查询计算机系全体学⽣的姓名。
select sname from student where sdept=’计算机系’;
5.查询年龄在20岁以下的学⽣的姓名及年龄。
select sname,sage from student where sage<20;
6.查询考试成绩有不及格的学⽣的学号
select distinct sno from sc where grade<60;
7.查询成绩在70~80分之间的学⽣,包括学号,课程号和成绩
select sno,cno,grade from sc where grade between 70 and 80;
integrity的词根词缀如何制作网页线上答题并生成证书8.查询年龄在20~23岁之间的学⽣的姓名、所在系和年龄。
select sname,sdept,sage from student where sage between 20 and 30;
9.查询年龄不在20~23之间的学⽣姓名、所在系和年龄。
select sname,sdept,sage from student where sage not between 20 and 30;
10.查询信息系和计算机系学⽣的姓名和性别。
select sname,ssex from student where sdept in (‘信息系’,’计算机系’);
11.查询既不是信息系,也不是计算机系学⽣的姓名和性别。
select sname,ssex from student where sdept not in (‘信息系’,’计算机系’);
12.查询姓‘张’的学⽣的详细信息。
select * from student where sname like ‘张%’;
13.查询所有不姓“刘”的学⽣。
select * from student where sname not like ‘刘%’;
14.查询⽆考试成绩的学⽣的学号和相应的课程号。
select sno,cno from sc where grade is null;
15.查询所有有考试成绩的学⽣的学号和课程号。
select sno,cno from sc where grade is not null;
16.将学⽣按年龄的升序排序。
select * from student order by sage;
17.查询选修了‘c02’号课程的学⽣的学号及其成绩,查询结果按成绩降序排列
select sno,grade from sc where cno=‘c02’ order by grade desc;
18.查询全体学⽣的信息,查询结果按所在系的系名升序排列,同⼀系的学⽣按年龄降序排列。
select * from student order by sdept asc,sage desc;
19.查询计算机系年龄在18~20之间,且性别为男的学⽣,包括姓名和年龄
select sname,sage from student where sdept=‘计算机系’ and sage between 18 and 20 and ssex=‘男’;聚合函数
20.统计学⽣总⼈数。
select count() from student;
21.统计选修了课程的学⽣的⼈数。
select count(distinct sno) from sc;
22.计算9512101号学⽣的考试总成绩之和。
select sno,sum(grade) from sc where sno=’9512101’;
23.计算’C01’号课程学⽣的考试平均成绩。
select avg(grade) from sc where cno=’c01’;
24.查询选修了’C01’号课程的学⽣的最⾼分和最低分。
select max(grade),min(grade) from sc where cno=’c01’;
25.查询计算机系学⽣的最⼤年龄和最⼩年龄
select max(sage),min(sage) from student where sdept=’计算机系’;
26.统计每个系的学⽣⼈数
select sdept,count() from student group by sdept;
27.统计每门课程的选课⼈数和考试最⾼分
select cno,count(),max(grade) from sc group by cno;
28.统计每名学⽣的选课门数和平均成绩。
select sno,count(),avg(grade) from sc group by sno;
29.查询修课门数等于或⼤于4门的学⽣的平均成绩和选课门数。
select sno,avg(grade),count() from sc group by sno having count >= 4;
30.统计每个学⽣的选课门数和考试总成绩,并按选课门数升序显⽰结果
select sno,count(),sum(grade) from sc group by sno order by count(*) asc;排序算法 python
31.查询总成绩超过200分的学⽣,要求列出学号,总成绩
select sno,sum(grade) from sc group by sno having sum(grade)>200;
⽤表连接完成
32.查询选修”c02”课程的学⽣的姓名和所在院系
select sname,sdept from student,sc where student.sno=sc.sno and cno=’c02’;
33.查询成绩80分以上学⽣的姓名、课程号和成绩,并按成绩降序排列结果
select sname,cno,grade from student,sc where student.sno=sc.sno and grade>80 order by grade desc;
34.查询所有修了VB课程的学⽣的修课情况,要求列出学⽣姓名和所在的系。
select sname,sdept from student,sc,course where student.sno=sc.sno and sco=courseo and cname=‘VB’;
35.查询信息系修了VB课程的学⽣的修课成绩,要求列出学⽣姓名、课程名和成绩。
select sname,cname,grade from student,sc,course where student.sno=sc.sno and sco=courseo and cname=‘VB’;
36.查询哪些课程没有⼈选,要求列出课程号,课程名
select cno,cname from course where cno not in (select distinct cno from sc);
⼆题:
根据3题的表完成下列操作
Select 查询语句
查询
1查询年龄在19⾄21岁之间的⼥⽣的学号,姓名,年龄。
select sno,name,sage from student where ssex=‘⼥’ sage between 19 and 21;
2查询姓名中第2个字为“明”字的学⽣学号、性别。
select sno,ssex from student where sname like ‘_明%’;
3查询 1001课程没有成绩的学⽣学号、课程号
select sno,cno from sc where cno=’1001’ and grade is null;
4查询JSJ 、SX、WL 系的年龄⼤于25岁的学⽣学号,姓名
select sno,sname from student where sdept in (‘JSJ’,’SX’,’WL’) and sage >25;
5查询 student 表中的学⽣共分布在那⼏个系中。
select distinct sdept from student;
6查询0001号学⽣1001课程的成绩。
select grade from sc where sno=’0001’ and cno=’1001’;
统计mysql面试题sql
1查询姓名中有“明”字的学⽣⼈数。
select count(*) from student where sname like ‘%明%’;
2计算‘JSJ’系的平均年龄及最⼤年龄。
select avg(sage),max(sage) from student where sdept=’JSJ’;
三题:
1.查询成绩为⼤于90分的学⽣的学号、姓名。
select student.sno,sname from student,sc where student.sno=sc.sno and grade>90;
2.查询数学系成绩80分以上的学⽣的学号、姓名
select student.sno,sname from student,sc where student.sno=sc.sno and sdept=’数学系’ and grade>80;
3.查询选修了“数据库基础”课程的学⽣的学号、姓名。
select student.sno,sname from student,sc,course where student.sno=sc.sno and sco=courseo and cname=’数据库基础’;
4.查询修了‘c02’课程且成绩⾼于此课程的平均成绩的学⽣的学号和成绩。
select sno,grade from sc where cno=’c02’and sno > (select avg(grade) from sc where cno=’c02’);
5.查询计算机系考试成绩最⾼的学⽣的姓名
select sname from student,sc where student.sno=sc.sno and sdept=‘计算机系’ and grade=(select max(grade) from
sc,student where student.sno=sc.sno and sdept=‘计算机系’);
四题:
Select 查询语句
1.计算每⼀门课的总分、平均分,最⾼分、最低分.
select cno,sum(grade),avg(grade),max(grade),min(grade) from sc group by cno;
2.查询平均分⼤于80分的学⽣学号及平均分
select sno,avg(grade) from sc where group by sno having avg(grade)>80;
3.统计选修课程超过 2 门的学⽣学号
select sno from sc group by sno having count(*)>2;
数据库工程师培训课程目录4.统计平均分不及格的学⽣学号
select sno from sc group by sno having avg(grade)<60;
根据之前练习题中建⽴教学数据库的五个基本表:
学⽣表(学号,姓名,性别,年龄),student((Sno, sname, ssex,sage) ;
课程表(课程号,课程名,学分),Course (Cno, Cname, credit) ;
选课表(学号,课程号,成绩),SC (Sno, Cno, grade ) ;
教师表(教师号,姓名,性别,出⽣年⽉,系部,职称,地址),
T(Tno,Tname,ssex,birthday,dept,title,address) ;
⼯资表(教师号,基本⼯资,职务⼯资,合计),Salary(Tno,jbgz,zwgz,hj);
多表查询,⽤select检索
(1)查询教师的收⼊情况,包括教师号、姓名及⽉总收⼊。
,tname,hj from t,salary;
(2)查询每个学⽣的学号、姓名、选修课程及成绩。
select student.sno,sname,cname,grade from student,course,sc where student.sno=sc.sno and courseo=sco;(3)查询选修2号课程且成绩在90分以上的所有学⽣。
select sname from student,sc where student.sno=sc.sno and cno=’2’and grade>90;
(4)查询与王五在同⼀个系学习的学⽣。
select * from student where sdept in (select sdept from student where sdept=’王五’);
五题:
nongfu spring怎么读1.select sname from S where s# in(select s# from SC where c# in(select c# from C where tname=’刘⽼师’));
2.select sname from s where s# in(select s# from sc where c#=’c2’) and s# in(select s# from sc where c#=’c4’);
3.select sname from s where s# in (select s# from sc group by s# having count(*)=(select count(c#) from c));
4.select cname from c,sc where c.c#=sc.c# group by sc.c# having avg(grade)>80;
5.select s#,avg(grade) from sc group by s#;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论