a2.sql 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. -- Current term is 1185
  2. /*
  3. The student number and name of second year students who have obtained
  4. a grade lower than 65 in at least two courses in a department with the
  5. name “computer science”.
  6. */
  7. select distinct sname, snum from student where year = 2 and snum in
  8. (
  9. select snum from mark where grade < 65 and deptcode in
  10. (
  11. select deptcode from department where deptname = "computer science"
  12. ) having count(distinct section) > 1
  13. )
  14. /*
  15. The number and name of professors who are not in the pure math (PM)
  16. department, and who are teaching CS245 for the first time.
  17. */
  18. select distinct pnum, pname from professor where deptcode not in
  19. (
  20. select deptcode fromm department where deptname = "PM"
  21. ) and pnum in
  22. (
  23. select pnum from class where deptcode = "CS" and cnum = 245
  24. ) having count(distinct term) = 1
  25. /*
  26. The number, name and year of each student who has obtained a grade in
  27. CS240 that is within 3 marks of the highest ever grade recorded for that
  28. course.
  29. */
  30. select distinct snum, sname, year from student where snum in
  31. (
  32. select snum, grade from mark where deptcode = "CS" and cnum = 240 and snum >= (select max(grade) from mark where deptcode = "CS" and cnum = 240)
  33. )
  34. /*
  35. The number and name of students who have completed two years, who
  36. have a final grade of at least 85 in every computer science course that
  37. they have taken, and who have always been taught by a professor in the
  38. computer science (CS) department.
  39. ASSUMING THIS PROFESSOR RESTRICTION ONLY APPLIES TO THE CS COURSES
  40. */
  41. select distinct snum, sname from student where year > 2 and snum not in
  42. (
  43. select snum, grade from mark where deptcode = "CS" and grade < 85
  44. ) and snum not in
  45. (
  46. select snum as prev_snum, deptcode as prev_deptcode, cnum as prev_cnum, term as prev_term, section as prev_section from mark where cnum in
  47. (
  48. select pnum, cnum from class where prev_deptcode = deptcode and prev_cnum = cnum and prev_term = term and prev_section = section and pnum in
  49. (
  50. select pnum from professor where deptcode = prev_deptcode
  51. )
  52. )
  53. )
  54. /*
  55. A sorted list of all departments who do not have a professor currently
  56. teaching a course offered by a different department.
  57. */
  58. select deptname as prof_dept from department where deptcode not in
  59. (
  60. select deptcode as old_dept, pnum as old_pnum from professor where pnum in
  61. (
  62. select pnum from class where term = 1185 and deptcode != old_dept and pnum = old_pnum
  63. )
  64. ) order by deptname
  65. /*
  66. For each pair of classes for the same course that were taught in the same
  67. term, and that where also taught by different professors: the minimum
  68. grades obtained and the maximum grades obtained. In addition to these
  69. four values, each result should include the number and name of each professor,
  70. as well as the identifying attributes for each class.
  71. */
  72. /*
  73. Pairs of distinct professors such that whenever the first one teaches a class
  74. in a particular term the second also teaches a class for the same course
  75. in the same term. Report a oprofessor number and name for both the
  76. professors.
  77. */
  78. -- NOW CAN USE AGGREGATION
  79. /*
  80. The course number and total enrollment count for all of its classes of each
  81. course. Also, include only those course numbers for courses with a total
  82. enrollment count among the three lowest such counts.
  83. */
  84. /*
  85. The percentage of professors in pure math who have always taught no
  86. more than a single course in any given term. (Note that a percentage
  87. should be a number between 0 and 100.)
  88. */
  89. /*
  90. The number of different third or fourth year students in each section of
  91. each course taught by a pure math professor in past terms. The result
  92. should include the professor number, professor name, course number and
  93. section, and should also be sorted first by the name of the professor,
  94. then by the professor number, third by the course number, and finally by
  95. section. (Note that a section is identified by a term and a section number.
  96. Also assume that sorting by section means sorting by term and then by
  97. section number. The result will therefore have a total of six columns.)
  98. */
  99. /*
  100. The ratio of professors in pure math (PM) to professors in applied math
  101. (AM) who have taught a class in which the average grade obtained in the
  102. class was greater than 77.
  103. */
  104. /*
  105. For the current term, report how many courses there are in the schedule
  106. with a particular number of classes. For example an output
  107. {[5, 1], [4, 2], [1, 5]}
  108. indicates that there are 5 courses with a single class (section), 4 courses
  109. with 2 classes, and 1 course with 5 classes scheduled in the curent term.
  110. */