Question: For a given quarter, the table Student lists all students registered at the University, the table Course lists all courses offered, and the table Enrollment
For a given quarter, the table Student lists all students registered at the University, the table Course lists all courses offered, and the table Enrollment encodes the students that attend any course in the current quarter.
Student (Sid, Sname)
Course (Cid, Cname)
Enrollment (Cid, Sid)
Enrollement.sid is a foreign key that references Student.sid.
Enrollement.cid is a foreign key that references Course.cid.
1. A classmate of a student is another student who is enrolled in at least one same class. Write a SQL query that returns all students with all of their classmates. You should return their student IDs, as their names do not uniquely identify them.
2. Write a SQL query that computes for each student id in the Student table the total number of different classmates that this student has across all courses. Note that a student may be so busy with research (or parties :-)) that he or she may choose not to enroll to any course that quarter, and hence has no classmates. Such students should still appear in the result, with 0 as the number of their classmates.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
