数据库原理第二次实验

2020-11-12  本文已影响0人  楚木巽

一 实验目的

二 实验过程

创建查询

编写SQL语句

1. Print the name of professors who work in departments that have fewer than 50 phD students.

q1.png

2. Print the name(s) of student(s) with the lowest gpa.

q2.png

3. For each Computer Sciences class, print the cno, sectno and the average gpa of the student enrolled in the class.

q3.png

4. Print the course names, course numbers and section numbers of all classes with less than six students enrolled in them.

q4.png

5. Print the name(s) and sid(s) of the student(s) enrolled in the most classes.

q5.png

6. Print the names of departments that have one or more majors who are under 18 years old.

q6.png

7. Print the names and majors of students who are taking one of the College Geometry courses. (Hint: You'll need to use the "like" predicate and the string matching character in your query.)

q7.png

8. For those departments that have no majors taking a College Geometry course, print the department name and the number of PhD students in the department.

q8.png

9. Print the names of students who are taking both a Computer Sciences course and a Mathematics course.

q9.png

10. Print the age difference between the oldest and youngest Computer Sciences major(s).

q10.png

11. For each department that has one or more majors with a GPA under 1.0, print the name of the department and the average GPA of its majors.

q11.png

12. Print the ids, names, and GPAs of the students who are currently taking all of the Civil Engineering courses.

q12.png

在做作业的过程中犯的一些错误及经验

  1. WHERE后面不能跟聚合函数语句
  2. 嵌套的里层的语句不能使用外层声明的范围变量
  3. round(对应数字,保留位数)可以保留相应的小数点位数
  4. 除了子查询在主查询的FROM子句中使用的EXISTS保留字的情况下可以返回多个字段外,其他情况子查询的SELECT后面只能返回一个字段
    5.查询某个具体字段时一定要记得加单引号!
    6.Access中似乎没有INTERSECT函数,也不支持EXCEPT函数
  1. 通过最终需要得到的结果作为驱动找到所有相关的表
  2. 从相关的表中找到对应结果的属性直接先写在第一个SELECT的后面
  3. 从这些需要得到的属性再去倒推表与表之间的关系,进行表与表之间的连接等操作
    不得不说写语句这东西真的是熟能生巧,虽然中途也遇到了各种各样的问题,花费了很多的时间,但是确实如老师所说的,写完这12条语句对sql查询的就差不多算是全部掌握了,做完以后确实有一种恍然大悟的感觉,对表与表之间的连接、嵌套等操作也更加清晰了。
上一篇下一篇

猜你喜欢

热点阅读