zoukankan      html  css  js  c++  java
  • 数据库笔记(三)

    学习内容


    来自上课老师讲的题目
    

    具体代码

    1.查询每人的成绩(学号、课程号、成绩)和所有成绩平均分;

    select * , ( select AVG(DEGREE) from SCORE ) av 
    from SCORE
    

    2.查询每人的成绩(学号、课程号、成绩)和本课程平均分;

    select * , (select AVG(DEGREE) from SCORE where cno = sc.cno) av
    from SCORE sc
    

    3.查询每人的成绩(学号、姓名,课程名、成绩)和本班总平均分;

    select s.sno, sname, cname, degree,
    ( select AVG(DEGREE) from STUDENT s1 join SCORE sc1 on s1.sno = sc1.sno where s1.class = s.class ) av
    from STUDENT s join SCORE sc on s.sno = sc.sno
    join COURSE c on c.cno = sc.cno
    

    4.查询每人的成绩(学号、姓名,课程名、成绩)和本班本科平均分;

    select s.sno, sname, cname, degree,
    ( select AVG(DEGREE) from STUDENT s1 join SCORE sc1 on s1.sno = sc1.sno where s1.class = s.class and sc1.cno = sc.cno ) av
    from STUDENT s join SCORE sc on s.sno = sc.sno
    join COURSE c on c.cno = sc.cno 
    

    5.查询成绩高于学号为“101”的课程号为“3-105”的成绩的所有记录。

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

    6.查询和学号为101的同学同月出生的所有学生的Sno、Sname和Sbirthday列。

    select sno, sname, sbirthday from STUDENT
    where MONTH(SBIRTHDAY) = ( select MONTH(SBIRTHDAY) from STUDENT where sno = '101' )
    

    7.查询“张旭“教师任课的学生成绩(学号、姓名,课程名、成绩)。

    select s.sno, sname, cname, degree from STUDENT s 
    join SCORE sc on s.sno = sc.sno 
    join COURSE c on c.cno = sc.cno
    where tno = ( select tno from TEACHER where tname = '张旭' )
    

    8.查询每科的最高分信息(学号、姓名,课程名、成绩)

    select s.sno, sname, cname, degree from STUDENT s 
    join SCORE sc on s.sno = sc.sno
    join COURSE c on c.cno = sc.cno
    where degree >= all( select degree from SCORE where cno = c.cno )
    --where degree = ( select MAX(DEGREE) from SCORE where cno = c.cno )
    

    9.查询有成绩不及格的同学的学号,姓名。

    select sno, sname from STUDENT where sno in ( select sno from SCORE where degree<60 )
    --select sno, sname from STUDENT s where 60> any( select sno from SCORE where sno = s.sno )
    --select sno, sname from STUDENT s where exists ( select sno from SCORE where degree<70 and sno = s.sno )
    

    10. 查询选修两门及两门以上课程的学生学号及姓名,课程名,成绩,并保存到’SC’表中。

    select s.sno, sname, cname, degree from STUDENT s 
    join SCORE sc on s.sno = sc.sno
    join COURSE c on c.cno = sc.cno 
    where ( select COUNT(*) from SCORE where sno = s.sno )>1
    

  • 相关阅读:
    洛谷P3959 宝藏(状压dp)
    洛谷P3645 [APIO2015]雅加达的摩天楼(最短路+分块)
    洛谷P3646 [APIO2015]巴厘岛的雕塑(数位dp)
    洛谷P4770 [NOI2018]你的名字(后缀自动机+线段树)
    洛谷P4768 [NOI2018]归程(克鲁斯卡尔重构树+最短路)
    hive3.1.1 hive-site.xml
    mysql 远程连接数据库的二种方法
    linux彻底干干净净完全卸载 mysql
    jdk环境变量配置
    Eclipse常用快捷键
  • 原文地址:https://www.cnblogs.com/hyj-/p/12750337.html
Copyright © 2011-2022 走看看