Vous êtes sur la page 1sur 2

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 om!uter "cience de!artment in Fall ##. $ %& ' ()*"+ >< $+,-*./+0.1 23+*+ 'course4number & 43801 -0$ 'de!artment4name & om!uter "cience1 " %& ' $ >< ' "+ .5(0 23+*+ semester&Fall ## 1 16section4id7 ." %& '' " >< .*-0" *5,.1 >< ".)$+0.16lastname, firstname, major7 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. S is all students ta!in" any of the sections in CS. 8. Find the first name and last name of all instructors 9ho taught the course 4380 offered by the om!uter "cience de!artment. 50 %& ' $ >< "+ .5(016instructor4id7 508 %& '50 >< 50".*) .(*16firstname, lastname7 Note. CD is the same as abo#e. $N is the id of instructor %ho tau"ht any section of course 4380 from Computer Science Department. $N& is the result %hich has the name of the instructors. 3. Find the number and de!artment identifier of all courses in 9hich no student e:er got an F. F"ections %& '.*-0" *5,. 9here grade & ;F<16section4id7 F %& 'Fsections >< "ection16course4number, de!t4id7 0oF %& ' ()*"+6course4number, de!t4id71 = F Note. Fsections are the identifiers of all section in %hich a student "ot an F. FC is all courses '"i#en by course number and department id( in %hich a student "ot an F. Finally) NoF is the result. *e ta!e all courses and subtract from this the courses in %hich a student "ot an F.

4. Find the identifier of all instructors 9ho are teaching at least three sections of a course in the same semester. "1'section4id1, section4number1, course4number1, de!t4id1, semester1, instructor4id11 %& "+ .5(0'section4id, section4number, course4number, de!t4id, semester, instructor4id1 "8'section4id8, section4number8, course4number8, de!t4id8, semester8, instructor4id81 %& "+ .5(0'section4id, section4number, course4number, de!t4id, semester, instructor4id1 .em!1 %& '"1 > "8 > "+ .5(01 23+*+ 'course4number & course4number11 -0$ 'course4number & course4number81 -0$ 'course4number1 & course4number81 .em!8 %& .em!1 23+*+ 'instructor4id & instructor4id11 -0$ 'instructor4id & instructor4id81 -0$ 'instructor4id1 & instructor4id81 .em!3 %& .em!8 23+*+ 'de!t4id & de!t4id11 -0$ 'de!t4id & de!t4id81 -0$ 'de!t4id1 & de!t4id81 .em!4 %& .em!3 23+*+ 'semester & semester11 -0$ 'semester & semester81 -0$ 'semester1 & semester81 .em!? %& .em!4 23+*+ 'section @A section11 -0$ 'section1 @A section81 -0$ 'section @A section81 Note. *e first create three different copies of the S+C $,N relation. hen) %e ta!e the cartesian product. he cartesian product contains combinations of three tuples) all comin" from the section relation. *e are no% loo!in" for a tuple in the cartesian product that is composed of three different tuples from the S+C $,N relation) each tuple is for the same professor) same course number) same department id and the same semester) the three sections are different. he result is then %hat %e are loo!in" for. ?. Find the identifier of all students 9ho took all the reBuired courses for their majors =e:en if they do not ha:e a grade for some of the courses yet. "* %& '".)$+0. >< *+C)5*+/+0.16sid, course4number, de!artment4id7 " %& '"+ .5(0 >< .*-0" *5,.16sid, course4number, de!artment4id7 *eBs0ot.aken %& '"* = " 16sid7 .aken-ll %& ".)$+0.6sid7 = *eBs0ot.aken Note. S- is the re.uirements for each student. SC is the all courses students ha#e ta!en. -e.sNot a!en is the identifier of all students %ho ha#e not ta!en a re.uired course. $f %e subtract this from all students) %e are left %ith student %ho ha#e ta!en all their re.uired courses.