HW #1 Suggested Solutions 1. Find the last name, first name and major of all students taking any section of the course “4380” offered by the “Computer Science” department in “Fall 99”. CD := (COURSE DEPARTMENT) WHERE (course_number = 4380) AND (department_name = “Computer Science”) CS := (CD ( SECTION WHERE semester=”Fall 99” ) )[section_id] TS := ((CS TRANSCRIPT) STUDENT)[lastname, firstname, major] Note: CD is all courses numbered 4380 offered by the Computer Science Department. CS is the identifier of all sections of this course offered in Fall99. TS is all students taking any of the sections in CS. 2. Find the first name and last name of all instructors who taught the course “4380” offered by the “Computer Science” department. IN := (CD SECTION)[instructor_id] IN2 := (IN INSTRUCTOR)[firstname, lastname] Note. CD is the same as above. IN is the id of instructor who taught any section of course 4380 from Computer Science Department. IN2 is the result which has the name of the instructors. 3. Find the number and department identifier of all courses in which no student ever got an “F”. FSections := (TRANSCRIPT where grade = ‘F’)[section_id] FC := (Fsections Section)[course_number, dept_id] NoF := (COURSE[course_number, dept_id]) – FC Note. Fsections are the identifiers of all section in which a student got an F. FC is all courses (given by course number and department id) in which a student got an F. Finally, NoF is the result. We take all courses and subtract from this the courses in which a student got an F. 4. Find the identifier of all instructors who are teaching at least three sections of a course in the same semester. S1(section_id1, section_number1, course_number1, dept_id1, semester1, instructor_id1) := SECTION(section_id, section_number, course_number, dept_id, semester, instructor_id) S2(section_id2, section_number2, course_number2, dept_id2, semester2, instructor_id2) := SECTION(section_id, section_number, course_number, dept_id, semester, instructor_id) Temp1 := (S1 x S2 x SECTION) WHERE (course_number = course_number1) AND (course_number = course_number2) AND (course_number1 = course_number2) Temp2 := Temp1 WHERE (instructor_id = instructor_id1) AND (instructor_id = instructor_id2) AND (instructor_id1 = instructor_id2) Temp3 := Temp2 WHERE (dept_id = dept_id1) AND (dept_id = dept_id2) AND (dept_id1 = dept_id2) Temp4 := Temp3 WHERE (semester = semester1) AND (semester = semester2) AND (semester1 = semester2) Temp5 := Temp4 WHERE (section <> section1) AND (section1 <> section2) AND (section <> section2) Note. We first create three different copies of the SECTION relation. Then, we take the cartesian product. The cartesian product contains combinations of three tuples, all coming from the section relation. We are now looking for a tuple in the cartesian product that is composed of three different tuples from the SECTION relation, each tuple is for the same professor, same course number, same department id and the same semester, the three sections are different. The result is then what we are looking for. 5. Find the identifier of all students who took all the required courses for their majors –even if they do not have a grade for some of the courses yet. SR := (STUDENT REQUIREMENT)[sid, course_number, department_id] SC := (SECTION TRANSCRIPT)[sid, course_number, department_id] ReqsNotTaken := (SR – SC)[sid] TakenAll := STUDENT[sid] – ReqsNotTaken Note. SR is the requirements for each student. SC is the all courses students have taken. ReqsNotTaken is the identifier of all students who have not taken a required course. If we subtract this from all students, we are left with student who have taken all their required courses.