mysql查询平均年龄最小的系_mysql数据库面试题带答案(二)

1题:

根据mysql数据库面试题(一)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;

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;

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 sc.cno=course.cno and cname=‘VB’;

35.查询信息系修了VB课程的学生的修课成绩,要求列出学生姓名、课程名和成绩。

select sname,cname,grade from student,sc,course where student.sno=sc.sno and sc.cno=course.cno and cname=‘VB’;

36.查询哪些课程没有人选,要求列出课程号,课程名

select cno,cname from course where cno not in (select distinct cno from sc);

二题:

根据mysql数据库面试题(一)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’;

统计

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 sc.cno=course.cno 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)查询教师的收入情况,包括教师号、姓名及月总收入。

select t.tno,tname,hj from t,salary;

(2)查询每个学生的学号、姓名、选修课程及成绩。

select student.sno,sname,cname,grade from student,course,sc where student.sno=sc.sno and course.cno=sc.cno;

(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=’王五’);

五题:

2244706edae60c6e89910ccbdbb7a6dd.png

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#;

  • 4
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值