• mysql select 练习题


    10、 查询Score表中的最高分的学生学号和课程号。(子查询或者排序)

    select sno,cno from score where degree  in(select max(degree) from score)

    11、查询每门课的平均成绩。

    select cno,avg(degree) from score group by cno

    12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数

     select avg(degree) from score where cno like'3%'and cno in(select  cno from score group by cno having count(*)>4)

    14、查询所有学生的SnameCnoDegree列。

    select score.cno,score.degree,student.sname from score,student where student.sno=score.sno

    16、查询所有学生的SnameCnameDegree列。

    select student.sname,course.cname,score.degree from score,course,student where student.sno=score.sno and course.cno=score.cno

    17 查询“95033”班学生的平均分。

    select avg(degree) from score where sno in (select sno from student where class='95033')

     18、假设使用如下命令建立了一个grade表:

    create table grade(low  int(3),upp  int(3),rank  char(1))

    insert into grade values(90,100,A)

    insert into grade values(80,89,B)

    insert into grade values(70,79,C)

    insert into grade values(60,69,D)

    insert into grade values(0,59,E)

    现查询所有同学的SnoCnorank列。

    1.select sno,cno, rank from score  join grade on degree between low and upp

    2.select sno,cno,rank from score,grade where degree between low and upp

    19  查询选修“3-105课程的成绩高于“109号同学成绩的所有同学的记录。

    1.Select * from score where cno=’3-105’ and degree>(select degree from score where sno=’109’)

    查询选修“3-105课程的并且成绩高于“109”号同学成绩的所有同学的记录。

    select * from score where cno='3-105' and degree>(select degree from score where sno='109' and cno='3-105' )

    20、查询score中选学多门课程的同学中分数为非最高分成绩的记录。

    select * from score where sno in(select sno from score group by sno having count(*)>1 ) and  degree not in(select max(degree) from score)

    21查询成绩高于学号为“109”、课程号为“3-105的成绩的所有记录。

    select * from score where degree>(select degree from score where sno='109' and cno='3-105' )

    22查询和学号为108的同学同年出生的所有学生的SnoSnameSbirthday列。

    select sno,sname,sbirthday from student where YEAR(sbirthday)=(select YEAR(sbirthday) from student where sno=’108’)

    23、查询“张旭“教师任课的学生成绩。

    select * from score  where cno in(select cno from course where tno=(select tno from teacher where tname='张旭'))

    24、查询选修某课程的同学人数多于5人的教师姓名。

    select tname from teacher where tno=(select tno from course  where cno=(select cno from score group by cno having count(*)>5))

    28、查询“计算机系”与“电子工程系“不同职称的教师的TnameProf

       select tname,prof from teacher where prof not in(select prof from teacher where depart=’计算机系’and prof in(select prof from teacher where depart=’电子工程系’))

    29、查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245的同学的CnoSnoDegree,并按Degree从高到低次序排序。

    select * from Score where Cno='3-105' and Degree>any(select Degree from Score where Cno =’3-245') order by Degree desc

    30、查询选修编号为“3-105且成绩高于选修编号为“3-245课程的同学的CnoSnoDegree.

    select * from Score where Cno='3-105' and Degree>all(select Degree from Score where Cno ='3-245')

    33 查询成绩比该课程平均成绩低的同学的成绩表。

    select * from score a where degree<(select avg(degree) from score b where b.cno=a.cno)

    34、查询所有任课教师的TnameDepart.

    select tname,depart from teacher where tno in(select tno from course where cno in(select cno from score))

    35 查询所有未讲课的教师的TnameDepart.

    select tname,depart from teacher where tno in(select tno from course where cno not in(select cno from score))

    37、查询Student表中不姓“王”的同学记录。

    select * from student where sname not like '%'

    38、查询Student表中每个学生的姓名和年龄。

    select sname,year(now())-year(sbirthday) from student

    41、查询“男”教师及其所上的课程

     select tname,cname from teacher,course where teacher.tno=course.tno and tsex=''

    42、查询最高分同学的SnoCnoDegree列。

    select sno,cno,degree  from score where degree=(select max(degree) from score)

    43、查询和“李军”同性别的所有同学的Sname.

    select sname from student where  ssex in(select ssex from student where sname='李军')

    44、查询和“李军”同性别并同班的同学Sname.

    select Sname from Student where Ssex = (select Ssex from Student where Sname='李军') and class in(select class from student where sname='李军')

    45、查询所有选修“计算机导论”课程的“男”同学的成绩表。 

    select * from score where cno in(select cno from course where cname='计算机导论') and sno in(select sno from student where ssex='')

     

  • 相关阅读:
    继承LIst 的类JSON序列化,无法序列化属性的问题
    C#深入学习:泛型修饰符in,out、逆变委托类型和协变委托类型
    12.Java web--过滤器与监听器
    11.Java web—servlet
    10.Java web—JavaBean
    9.Java web—JSP内置对象
    8.Java web—JSP基本语法
    Ubuntu 插入鼠标自动禁用触控板
    Ubuntu安装VLC播放器
    Ubuntu快捷键
  • 原文地址:https://www.cnblogs.com/zxl89/p/5981102.html
Copyright © 2020-2023  润新知