zoukankan      html  css  js  c++  java
  • MYSQL select查询练习题

    10、 查询Score表中的最高分的学生学号和课程号。(子查询或者排序)
     select sno,cno from score where degree=(select max(degree) from score)
     select * from score order by degree desc limit 0,1

    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)
     select avg(degree) from score group by cno having count(*)>4 and cno like '3%'

    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’)
    现查询所有同学的Sno、Cno和rank列。
     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 max(degree) from score where sno='109')
     (2)select * from score where cno = '3-105' and degree>(select max(degree) from score where sno='109' and cno='3-105')

    20、查询score中选学多门课程的同学中分数为非最高分成绩的记录。
     (1)select * from score where sno in(select sno from score group by sno having count(*)>1) and degree<(select max (degree) from score)

     (2)select * from score a where sno in(select sno from score group by sno having count(*)>1) and degree<(select max (degree) from score b where b.cno = a.cno)

    28、查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。
     select tname,prof from teacher where depart='计算机系'  and prof not in(select prof from teacher where depart='电子工程系')
    union
    select tname,prof from teacher where depart='电子工程系'  and prof not in(select prof from teacher where depart='计算机系')

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

    select tname,prof from teacher a where prof not in(select prof from teacher b where a.depart!=b.depart)
    29、查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。
     select * from score where cno='3-105' and degree>any(select degree from score where cno='3-245')
     select * from score where cno='3-105' and degree>(select min(degree) from score where cno='3-245')

    30、查询选修编号为“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 where cno='3-105' and degree>(select max(degree) from score where cno='3-245')

    36、查询至少有2名男生的班号。
     select class from student where ssex='男' group by class having count(*)>1

    38、查询Student表中每个学生的姓名和年龄。
     select sname,year(now())-year(sbirthday) from student;
     select sname,(DATE_FORMAT(from_days(to_days(now())-to_days(sbirthday)),'%Y')+0) as age from student;

    45、查询所有选修“计算机导论”课程的“男”同学的成绩表。
     select * from score where sno in(select sno from student where ssex='男') and cno in(select cno from course where cname='计算机导论');

     select student.sno,student.sname,student.ssex,student.sbirthday,student.class,course.cno,course.cname,score.degree from student,course,score where student.sno in (select sno from student where ssex='男') and course.cno in (select cno from course where cname='计算机导论') and student.sno=score.sno and course.cno=score.cno;

  • 相关阅读:
    CSS 中的字体兼容写法:用CSS为英文和中文字体分别设置不同的字体
    利用vue-cropper做的关于图片裁剪、压缩、上传、预览等做的一个公共组件
    解决浏览器拦截弹出窗口问题
    详解Vue中的nextTick
    vue里ref ($refs)用法
    vue组件的hover事件模拟、给第三方组件绑定事件不生效问题
    JS实现千分位
    JS实现异步编程的4种方法
    Cas_个人理解
    zabbix_监控_邮件预警
  • 原文地址:https://www.cnblogs.com/bujianchenxi/p/5983751.html
Copyright © 2011-2022 走看看